Skip to content

Commit

Permalink
wider default fsharp_max_value_binding_width, also take width of patt…
Browse files Browse the repository at this point in the history
…ern of binding into account (#1947)

Co-authored-by: Don Syme <donsyme@fastmail.fm>
  • Loading branch information
nojaf and dsyme committed Jan 14, 2022
1 parent fdb6050 commit 301e0d8
Show file tree
Hide file tree
Showing 30 changed files with 183 additions and 230 deletions.
9 changes: 5 additions & 4 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ fsharp_record_multiline_formatter=character_width
fsharp_max_array_or_list_width=40
fsharp_max_array_or_list_number_of_items=1
fsharp_array_or_list_multiline_formatter=character_width
fsharp_max_value_binding_width=40
fsharp_max_value_binding_width=80
fsharp_max_function_binding_width=40
fsharp_max_dot_get_expression_width=50
fsharp_multiline_block_brackets_on_same_column=false
Expand Down Expand Up @@ -704,8 +704,9 @@ let myArray =

### fsharp_max_value_binding_width

Control the maximum width for which let and member value bindings should be in one line.
Default = 40.
Control the maximum expression width for which let and member value/property bindings should be in one line.
The width is that of the pattern for the binding plus the implementating expression but not the keywords (e.g. "let").
Default = 80.

`defaultConfig`

Expand All @@ -729,7 +730,7 @@ type MyType() =

### fsharp_max_function_binding_width

Control the maximum width for which let and member function bindings should be in one line.
Control the maximum width for which function and member bindings should be in one line.
Default = 40.

`defaultConfig`
Expand Down
33 changes: 21 additions & 12 deletions fantomas.sln
Original file line number Diff line number Diff line change
@@ -1,24 +1,32 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15
VisualStudioVersion = 15.0.26124.0
# Visual Studio Version 17
VisualStudioVersion = 17.0.31825.309
MinimumVisualStudioVersion = 15.0.26124.0
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = ".paket", ".paket", "{B570C54C-2FEA-4A94-A8C5-FD4157A94DE7}"
ProjectSection(SolutionItems) = preProject
paket.dependencies = paket.dependencies
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas", "src\Fantomas\Fantomas.fsproj", "{7EA16279-A5F1-4781-A343-4375A04BCE6F}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas", "src\Fantomas\Fantomas.fsproj", "{7EA16279-A5F1-4781-A343-4375A04BCE6F}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Tests", "src\Fantomas.Tests\Fantomas.Tests.fsproj", "{DED76E41-B89F-47BA-84C5-3AB0BECFA767}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas.Tests", "src\Fantomas.Tests\Fantomas.Tests.fsproj", "{DED76E41-B89F-47BA-84C5-3AB0BECFA767}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.CoreGlobalTool", "src\Fantomas.CoreGlobalTool\Fantomas.CoreGlobalTool.fsproj", "{DC08805B-C6E2-43F3-B381-E60EE88A079D}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas.CoreGlobalTool", "src\Fantomas.CoreGlobalTool\Fantomas.CoreGlobalTool.fsproj", "{DC08805B-C6E2-43F3-B381-E60EE88A079D}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.CoreGlobalTool.Tests", "src\Fantomas.CoreGlobalTool.Tests\Fantomas.CoreGlobalTool.Tests.fsproj", "{DEDE6968-0BE8-4415-9262-8355B82AF2C0}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas.CoreGlobalTool.Tests", "src\Fantomas.CoreGlobalTool.Tests\Fantomas.CoreGlobalTool.Tests.fsproj", "{DEDE6968-0BE8-4415-9262-8355B82AF2C0}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Benchmarks", "src\Fantomas.Benchmarks\Fantomas.Benchmarks.fsproj", "{B6BC63D5-410D-4DBB-9D45-5638F20BD09B}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas.Benchmarks", "src\Fantomas.Benchmarks\Fantomas.Benchmarks.fsproj", "{B6BC63D5-410D-4DBB-9D45-5638F20BD09B}"
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Extras", "src\Fantomas.Extras\Fantomas.Extras.fsproj", "{4088FF76-1DB7-4E68-80FE-E851CE6701AC}"
Project("{6EC3EE1D-3C4E-46DD-8F32-0CC8E7565705}") = "Fantomas.Extras", "src\Fantomas.Extras\Fantomas.Extras.fsproj", "{4088FF76-1DB7-4E68-80FE-E851CE6701AC}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "docs", "docs", "{29F22904-C9E0-40AA-B971-9AE377C17F59}"
ProjectSection(SolutionItems) = preProject
docs\Documentation.md = docs\Documentation.md
docs\Formatting-Elmish-code.md = docs\Formatting-Elmish-code.md
docs\FormattingConventions.md = docs\FormattingConventions.md
docs\index.html = docs\index.html
EndProjectSection
EndProject
Project("{F2A71F9B-5D33-465A-A702-920D77279786}") = "Fantomas.Client", "src\Fantomas.Client\Fantomas.Client.fsproj", "{AA895F94-CCF2-4FCF-A9BB-E16987B57535}"
EndProject
Expand All @@ -31,9 +39,6 @@ Global
Release|x64 = Release|x64
Release|x86 = Release|x86
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{7EA16279-A5F1-4781-A343-4375A04BCE6F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{7EA16279-A5F1-4781-A343-4375A04BCE6F}.Debug|Any CPU.Build.0 = Debug|Any CPU
Expand Down Expand Up @@ -120,6 +125,10 @@ Global
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x86.ActiveCfg = Release|Any CPU
{AA895F94-CCF2-4FCF-A9BB-E16987B57535}.Release|x86.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {DEBFC920-A647-4859-890D-B59793D27594}
EndGlobalSection
EndGlobal
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,9 @@ type MNIST
?targetTransform: Tensor -> Tensor
) =
inherit Dataset()
let path =
Path.Combine(path, "mnist") |> Path.GetFullPath
let path = Path.Combine(path, "mnist") |> Path.GetFullPath
let train = defaultArg train true
let transform =
defaultArg transform (fun t -> (t - 0.1307) / 0.3081)
let transform = defaultArg transform (fun t -> (t - 0.1307) / 0.3081)
let targetTransform = defaultArg targetTransform id
let urls =
List.ofSeq
Expand Down
10 changes: 3 additions & 7 deletions src/Fantomas.Tests/CastTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -92,14 +92,11 @@ open System.Threading.Tasks
open Amazon.Runtime
let waitAndUpcast (x: Task<'t>) =
let t =
x |> Async.AwaitTask |> Async.RunSynchronously
let t = x |> Async.AwaitTask |> Async.RunSynchronously
x.Result :> AmazonWebServiceResponse
let waitAndUpcast (x: Task<'t>) =
let t =
x |> Async.AwaitTask |> Async.RunSynchronously
let t = x |> Async.AwaitTask |> Async.RunSynchronously
x.Result :> AmazonWebServiceResponse
"""
Expand Down Expand Up @@ -131,8 +128,7 @@ open System.Threading.Tasks
open Amazon.Runtime
let waitAndUpcast (x: Task<'t>) =
let t =
x |> Async.AwaitTask |> Async.RunSynchronously
let t = x |> Async.AwaitTask |> Async.RunSynchronously
x.Result :?> AmazonWebServiceResponse
"""
Expand Down
10 changes: 5 additions & 5 deletions src/Fantomas.Tests/ClassTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -339,8 +339,7 @@ let ``should keep parens in class inheritance in the right place`` () =
class
inherit DGMLClass()
let functions =
System.Collections.Generic.Dictionary<string, IState>()
let functions = System.Collections.Generic.Dictionary<string, IState>()
end
"""

Expand Down Expand Up @@ -461,7 +460,9 @@ type T() =
member __.Property = "hello"
let longNamedFunlongNamedFunlongNamedFunlongNamedFunlongNamedFun (x: T) = x
let longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClass = T()
let longNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClasslongNamedClass =
T()
System.String.Concat(
"a",
Expand Down Expand Up @@ -751,8 +752,7 @@ indent_size=2
output
|> should startWith (sprintf \"Processing %s\" fileFixture.Filename)
let result =
System.IO.File.ReadAllText(fileFixture.Filename)
let result = System.IO.File.ReadAllText(fileFixture.Filename)
result
|> should
Expand Down
4 changes: 1 addition & 3 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2336,9 +2336,7 @@ module ReactHookExtensions =
type React with
[<Hook>]
static member useDeferred(operation: Async<'T>, dependencies: obj array) =
let (deferred, setDeferred) =
React.useState (Deferred.HasNotStartedYet)
let (deferred, setDeferred) = React.useState (Deferred.HasNotStartedYet)
let token = React.useCancellationToken ()
let executeOperation =
Expand Down
36 changes: 16 additions & 20 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -338,8 +338,7 @@ let tests =
equal
"""
[<Tests>]
let tests =
testList "tests" [ test "test" { Expect.equal true true "unexpected" } ]
let tests = testList "tests" [ test "test" { Expect.equal true true "unexpected" } ]
"""

[<Test>]
Expand Down Expand Up @@ -1020,10 +1019,7 @@ let ``let bang + let + return in ce`` () =
let getEvents () =
task {
let! cosmoEvents = eventStore.GetEvents EventStream AllEvents
let events =
List.map (fun (ce: EventRead<JsonValue, _>) -> ce.Data) cosmoEvents
let events = List.map (fun (ce: EventRead<JsonValue, _>) -> ce.Data) cosmoEvents
return events
}
"""
Expand Down Expand Up @@ -1052,10 +1048,7 @@ task {
.ConfigureAwait(false)
parameters.IssuerSigningKeys <- config.SigningKeys
let user, _ =
handler.ValidateToken((token: string), parameters)
let user, _ = handler.ValidateToken((token: string), parameters)
return Ok(user.Identity.Name, collectClaims user)
}
"""
Expand Down Expand Up @@ -1271,8 +1264,7 @@ let helloMachine =
handleOk sayHello }
let root =
freyaRouter {
resource "/hello{/name}" helloMachine }
freyaRouter { resource "/hello{/name}" helloMachine }
"""
config
|> prepend newline
Expand Down Expand Up @@ -1310,8 +1302,7 @@ let helloMachine =
handleOk sayHello
}
let root =
freyaRouter { resource "/hello{/name}" helloMachine }
let root = freyaRouter { resource "/hello{/name}" helloMachine }
"""

[<Test>]
Expand All @@ -1332,8 +1323,7 @@ promise {
|> should
equal
"""
let resource =
promise { return new DisposableAction(fun () -> isDisposed := true) }
let resource = promise { return new DisposableAction(fun () -> isDisposed := true) }
promise {
use! r = resource
Expand Down Expand Up @@ -1745,7 +1735,7 @@ let ``don't add extra newline before do bang`` () =
do! webPushClient.SendNotificationAsync(ps, payload, vapidDetails)
with :? WebPushException as wpex ->
log.LogError(sprintf "Couldn't send notification to %s, %A" user.UserId wpex)
do! filterSubscriptionsAndPersist
do! filterSubscriptionsAndPersistLongLongLongLongLongLongLongLongLong
managementToken
user.UserId
subscriptions
Expand All @@ -1767,14 +1757,20 @@ let sendPushNotifications =
|> List.map (fun s ->
task {
try
let ps =
PushSubscription(s.Endpoint, s.P256DH, s.Auth)
let ps = PushSubscription(s.Endpoint, s.P256DH, s.Auth)
do! webPushClient.SendNotificationAsync(ps, payload, vapidDetails)
with
| :? WebPushException as wpex ->
log.LogError(sprintf "Couldn't send notification to %s, %A" user.UserId wpex)
do! filterSubscriptionsAndPersist managementToken user.UserId subscriptions s.Origin s.Endpoint
do!
filterSubscriptionsAndPersistLongLongLongLongLongLongLongLongLong
managementToken
user.UserId
subscriptions
s.Origin
s.Endpoint
}
:> Task)
|> Task.WhenAll)
Expand Down
13 changes: 4 additions & 9 deletions src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -731,8 +731,7 @@ let foldi (folder: 'State -> int -> 'T -> 'State) (state: 'State) (array: 'T [])
if array.Length = 0 then
state
else
let folder =
OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt folder
let folder = OptimizedClosures.FSharpFunc<_, _, _, _>.Adapt folder
let mutable state: 'State = state
let len = array.Length
Expand Down Expand Up @@ -921,9 +920,7 @@ with
equal
"""
try
let defaultTime =
(DateTime.FromFileTimeUtc 0L).ToLocalTime()
let defaultTime = (DateTime.FromFileTimeUtc 0L).ToLocalTime()
foo.CreationTime <> defaultTime
with
// hmm
Expand All @@ -950,8 +947,7 @@ with
equal
"""
try
let defaultTime =
(DateTime.FromFileTimeUtc 0L).ToLocalTime()
let defaultTime = (DateTime.FromFileTimeUtc 0L).ToLocalTime()
foo.CreationTime <> defaultTime
with
Expand Down Expand Up @@ -1087,8 +1083,7 @@ module Foo =
// blah
let exists =
try
let defaultTime =
(DateTime.FromFileTimeUtc 0L).ToLocalTime ()
let defaultTime = (DateTime.FromFileTimeUtc 0L).ToLocalTime ()
foo.CreationTime <> defaultTime
with
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/DisableElmishTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,7 @@ let v =
|> should
equal
"""
let v =
someFunctionHere [ parameters ] [ yetMoreParameters ] :?> _
let v = someFunctionHere [ parameters ] [ yetMoreParameters ] :?> _
"""

[<Test>]
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,7 @@ module Services =
)
.Resolve
| Storage.EventStore (gateway, cache) ->
let accessStrategy =
Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
let accessStrategy = Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
let cacheStrategy =
Equinox.EventStore.CachingStrategy.SlidingWindow(cache, TimeSpan.FromMinutes 20.)
Expand Down
6 changes: 2 additions & 4 deletions src/Fantomas.Tests/ElmishTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -365,8 +365,7 @@ let ``div with long children but a long setting`` () =
|> should
equal
"""
let d =
div [] [ p [] [ str "fooooooooo" ]; p [] [ str "baaaaaaaar" ] ]
let d = div [] [ p [] [ str "fooooooooo" ]; p [] [ str "baaaaaaaar" ] ]
"""

// here the p is 38 characters
Expand Down Expand Up @@ -1007,8 +1006,7 @@ let private useLocationDetail (auth0 : Auth0Hook) (roles : RolesHook) id =
then
auth0.getAccessTokenSilently ()
|> Promise.bind (fun authToken ->
let url =
sprintf "%s/users/%s" Common.backendUrl (location.Creator)
let url = sprintf "%s/users/%s" Common.backendUrl (location.Creator)
fetch
url
Expand Down
20 changes: 5 additions & 15 deletions src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -627,12 +627,8 @@ module FormatCode =
module FormatCode =
let private format filename code config =
let checker =
Fantomas.FakeHelpers.sharedChecker.Force()
let options =
Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let checker = Fantomas.FakeHelpers.sharedChecker.Force()
let options = Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
Expand Down Expand Up @@ -668,12 +664,8 @@ module FormatCode =
module FormatCode =
let private format filename code config =
let checker =
Fantomas.FakeHelpers.sharedChecker.Force()
let options =
Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let checker = Fantomas.FakeHelpers.sharedChecker.Force()
let options = Fantomas.FakeHelpers.createParsingOptionsFromFile filename
let source = SourceOrigin.SourceString code
CodeFormatter.FormatDocumentAsync("tmp.fsx", source, config, options, checker)
Expand Down Expand Up @@ -978,9 +970,7 @@ module Infrastructure =
#if DEBUG
failwith message
#else
let sentryEvent =
SentryEvent(SentryMessage message, Level = errorLevel)
let sentryEvent = SentryEvent(SentryMessage message, Level = errorLevel)
()
#endif
"""
Expand Down
Loading

0 comments on commit 301e0d8

Please sign in to comment.