Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Fantomas tool and format F# code #573

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,19 @@ root = true
insert_final_newline = false
trim_trailing_whitespace = true
indent_style = space
indent_size = 2
indent_size = 2

##### F# files #####
[*.{fs,fsi,fsx}]

# Fantomas settings
max_line_length = 120 # default
# Max width of binding name plus binding definition, not including keywords
# Set to large value and let max_line_length split lines when necessary
fsharp_max_value_binding_width = 120
# Max width of function binding value, not including keywords and binding name
# Set to large value and let max_line_length split lines when necessary
fsharp_max_function_binding_width = 120
# Max width of series of dot-expression
# Set to large value and let max_line_length split lines when necessary
fsharp_max_dot_get_expression_width = 120
12 changes: 12 additions & 0 deletions src/.config/dotnet-tools.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"version": 1,
"isRoot": true,
"tools": {
"fantomas": {
"version": "6.1.1",
"commands": [
"fantomas"
]
}
}
}
14 changes: 8 additions & 6 deletions src/Elmish.WPF.Benchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,29 +9,31 @@ type public BenchmarkDynamicViewModel() =

[<GlobalSetup>]
member public x.GlobalSetup() =
let createBinding i =
Binding.oneWay id $"testBinding_%i{i}"
let createBinding i = Binding.oneWay id $"testBinding_%i{i}"

let bindings =
System.Linq.Enumerable.Range(0, x.BindingCount) |> Seq.map createBinding |> Seq.toList
System.Linq.Enumerable.Range(0, x.BindingCount)
|> Seq.map createBinding
|> Seq.toList

vm <- DynamicViewModel<int, obj>(ViewModelArgs.simple model, bindings)


[<Benchmark>]
member public x.Update() =
model <- 0

while model < x.UpdateCount do
model <- model + 1
IViewModel.updateModel (vm, model)

vm :> obj

[<Params (1, 10, 100)>]
[<Params(1, 10, 100)>]
member val public BindingCount = 0 with get, set

[<Params (1, 100, 10000)>]
[<Params(1, 100, 10000)>]
member val public UpdateCount = 0 with get, set


let _ = BenchmarkRunner.Run<BenchmarkDynamicViewModel>()
let _ = BenchmarkRunner.Run<BenchmarkDynamicViewModel>()
44 changes: 23 additions & 21 deletions src/Elmish.WPF.Tests/AutoOpen.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,44 +5,53 @@ module AutoOpen
type InvokeTester<'a, 'b>(f: 'a -> 'b) =
let mutable count = 0
let mutable values = []

let wrapped a =
count <- count + 1
values <- values @ [a]
values <- values @ [ a ]
f a

member __.Fn = wrapped
member __.Count = count
member __.Values = values
member __.Reset () =

member __.Reset() =
count <- 0
values <- []


type InvokeTester2<'a, 'b, 'c>(f: 'a -> 'b -> 'c) =
let mutable count = 0
let mutable values = []

let wrapped a b =
count <- count + 1
values <- values @ [a, b]
values <- values @ [ a, b ]
f a b

member __.Fn = wrapped
member __.Count = count
member __.Values = values
member __.Reset () =

member __.Reset() =
count <- 0
values <- []


type InvokeTester3<'a, 'b, 'c, 'd>(f: 'a -> 'b -> 'c -> 'd) =
let mutable count = 0
let mutable values = []

let wrapped a b c =
count <- count + 1
values <- values @ [a, b, c]
values <- values @ [ a, b, c ]
f a b c

member __.Fn = wrapped
member __.Count = count
member __.Values = values
member __.Reset () =

member __.Reset() =
count <- 0
values <- []

Expand All @@ -57,18 +66,11 @@ module String =
module List =

let swap i j =
List.permute
(function
| a when a = i -> j
| a when a = j -> i
| a -> a)

let insert i a ma =
(ma |> List.take i)
@ [ a ]
@ (ma |> List.skip i)

let replace i a ma =
(ma |> List.take i)
@ [ a ]
@ (ma |> List.skip (i + 1))
List.permute (function
| a when a = i -> j
| a when a = j -> i
| a -> a)

let insert i a ma = (ma |> List.take i) @ [ a ] @ (ma |> List.skip i)

let replace i a ma = (ma |> List.take i) @ [ a ] @ (ma |> List.skip (i + 1))
Loading