Skip to content

Commit

Permalink
Feature: MaxDotGetExpressionWidth (#1142)
Browse files Browse the repository at this point in the history
* First implementation for MaxDotGetExpressionWidth setting.

* Include TypeApp expressions in nested DotGetApp.

* Add documentation for fsharp_max_dot_get_expression_width.

* Bump to 4.2.0-alpha-001.
  • Loading branch information
nojaf authored Sep 18, 2020
1 parent 2968e2d commit 6eb91d8
Show file tree
Hide file tree
Showing 23 changed files with 392 additions and 153 deletions.
4 changes: 4 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
### 4.2.0-alpha-001 - 09/2020

* Feature MaxDotGetExpressionWidth. [#501](https://github.com/fsprojects/fantomas/issues/501)

### 4.1.1 - 09/2020

* Fix No newline between module and first declaration. [#1139](https://github.com/fsprojects/fantomas/issues/1139)
Expand Down
23 changes: 23 additions & 0 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@ fsharp_max_record_width=40
fsharp_max_array_or_list_width=40
fsharp_max_value_binding_width=40
fsharp_max_function_binding_width=40
fsharp_max_dot_get_expression_width=50
fsharp_multiline_block_brackets_on_same_column=false
fsharp_newline_between_type_definition_and_members=false
fsharp_keep_if_then_in_same_line=false
Expand Down Expand Up @@ -563,6 +564,28 @@ type Triangle() =
width * height / 2
```

### fsharp_max_dot_get_expression_width

Control the maximum width for which (nested) [SynExpr.DotGet](https://fsharp.github.io/FSharp.Compiler.Service/reference/fsharp-compiler-syntaxtree-synexpr.html) expressions should be in one line.
Default = 50.

`defaultConfig`

```fsharp
let job =
JobBuilder
.UsingJobData(jobDataMap)
.Create<WrapperJob>()
.Build()
```

`{ defaultConfig with MaxDotGetExpressionWidth = 100 }`

```fsharp
let job =
JobBuilder.UsingJobData(jobDataMap).Create<WrapperJob>().Build()
```

### fsharp_multiline_block_brackets_on_same_column

Alternative way of formatting records, arrays and lists. This will align the braces at the same column level.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<Version>4.1.1</Version>
<Version>4.2.0-alpha-001</Version>
<NoWarn>FS0988</NoWarn>
<WarningsAsErrors>FS0025</WarningsAsErrors>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.CoreGlobalTool/Fantomas.CoreGlobalTool.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>netcoreapp3.1</TargetFramework>
<ToolCommandName>fantomas</ToolCommandName>
<PackAsTool>True</PackAsTool>
<Version>4.1.1</Version>
<Version>4.2.0-alpha-001</Version>
<AssemblyName>fantomas-tool</AssemblyName>
<WarningsAsErrors>FS0025</WarningsAsErrors>
</PropertyGroup>
Expand Down
2 changes: 1 addition & 1 deletion src/Fantomas.Extras/Fantomas.Extras.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<Version>4.1.1</Version>
<Version>4.2.0-alpha-001</Version>
<Description>Utility package for Fantomas</Description>
<WarningsAsErrors>FS0025</WarningsAsErrors>
</PropertyGroup>
Expand Down
28 changes: 20 additions & 8 deletions src/Fantomas.Tests/CompilerDirectivesTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -323,20 +323,30 @@ let start (args: IArgs) =
|> should equal """let start (args: IArgs) =
// Serilog configuration
Log.Logger <-
LoggerConfiguration().MinimumLevel.Debug().MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext().WriteTo.Console().WriteTo.File(Path.Combine(args.ContentRoot, "temp/log.txt"))
LoggerConfiguration()
.MinimumLevel.Debug()
.MinimumLevel.Override("Microsoft", LogEventLevel.Information)
.Enrich.FromLogContext()
.WriteTo.Console()
.WriteTo.File(Path.Combine(args.ContentRoot, "temp/log.txt"))
.CreateLogger()
try
try
let giraffeApp = configureGiraffeApp args
WebHost.CreateDefaultBuilder().UseWebRoot(args.ClientPath)
WebHost
.CreateDefaultBuilder()
.UseWebRoot(args.ClientPath)
#if DEBUG
.UseContentRoot(args.ContentRoot).UseUrls(args.Host + ":" + string args.Port)
.UseContentRoot(args.ContentRoot)
.UseUrls(args.Host + ":" + string args.Port)
#endif
.UseSerilog().Configure(Action<IApplicationBuilder>(configureApp giraffeApp))
.ConfigureServices(configureServices args).Build().Run()
.UseSerilog()
.Configure(Action<IApplicationBuilder>(configureApp giraffeApp))
.ConfigureServices(configureServices args)
.Build()
.Run()
0
with ex ->
Expand Down Expand Up @@ -441,7 +451,8 @@ type FunctionComponent =
let elemType =
ReactBindings.React.``lazy`` (fun () ->
// React.lazy requires a default export
(importValueDynamic f).``then``(fun x -> createObj [ "default" ==> x ]))
(importValueDynamic f)
.``then``(fun x -> createObj [ "default" ==> x ]))
fun props ->
ReactElementType.create
Expand Down Expand Up @@ -645,7 +656,8 @@ type FunctionComponent =
let elemType =
ReactBindings.React.``lazy`` (fun () ->
// React.lazy requires a default export
(importValueDynamic f).``then``(fun x -> createObj [ "default" ==> x ]))
(importValueDynamic f)
.``then``(fun x -> createObj [ "default" ==> x ]))
fun props ->
ReactElementType.create
Expand Down
6 changes: 5 additions & 1 deletion src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -861,7 +861,11 @@ let ``let bang + do expression + let + return in ce`` () =
|> prepend newline
|> should equal """
task {
let! config = manager.GetConfigurationAsync().ConfigureAwait(false)
let! config =
manager
.GetConfigurationAsync()
.ConfigureAwait(false)
parameters.IssuerSigningKeys <- config.SigningKeys
let user, _ =
Expand Down
97 changes: 94 additions & 3 deletions src/Fantomas.Tests/DotGetTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<option<unit>>
""" config
|> prepend newline
|> should equal """
Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<option<unit>>>.GetGenericTypeDefinition()
Microsoft.FSharp.Reflection.FSharpType.GetUnionCases(typeof<option<option<unit>>>
.GetGenericTypeDefinition()
.MakeGenericType(t))
.Assembly
"""
Expand Down Expand Up @@ -43,7 +44,8 @@ let ``split chained method call expression, 246`` () =
root.SetAttribute
("driverVersion",
"AltCover.Recorder "
+ System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location)
+ System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly()
.Location)
.FileVersion)
"""

Expand Down Expand Up @@ -100,7 +102,8 @@ module Services =
snapshot: (('event -> bool) * ('state -> 'event))) =
match storage with
| Storage.MemoryStore store ->
Equinox.MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial).Resolve
Equinox.MemoryStore.Resolver(store, FsCodec.Box.Codec.Create(), fold, initial)
.Resolve
| Storage.EventStore (gateway, cache) ->
let accessStrategy =
Equinox.EventStore.AccessStrategy.RollingSnapshots snapshot
Expand All @@ -116,3 +119,91 @@ module Services =
accessStrategy)
.Resolve
"""

[<Test>]
let ``long chained expression should be multiline, 501`` () =
formatSourceString false """
module Program
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Serilog
open Startup
[<EntryPoint>]
let main args =
Host
.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(fun builder ->
builder
.CaptureStartupErrors(true)
.UseSerilog(dispose = true)
.UseStartup<Startup>()
|> ignore
)
.Build()
.Run()
0
""" config
|> prepend newline
|> should equal """
module Program
open Microsoft.AspNetCore.Hosting
open Microsoft.Extensions.Hosting
open Serilog
open Startup
[<EntryPoint>]
let main args =
Host
.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(fun builder ->
builder
.CaptureStartupErrors(true)
.UseSerilog(dispose = true)
.UseStartup<Startup>()
|> ignore)
.Build()
.Run()
0
"""

[<Test>]
let ``nested TypeApp inside DotGet`` () =
formatSourceString false """
let job =
JobBuilder
.UsingJobData(jobDataMap)
.Create<WrapperJob>()
.WithIdentity(taskName, groupName)
.Build()
""" config
|> prepend newline
|> should equal """
let job =
JobBuilder
.UsingJobData(jobDataMap)
.Create<WrapperJob>()
.WithIdentity(taskName, groupName)
.Build()
"""

[<Test>]
let ``TypeApp at end of nested DotGet`` () =
formatSourceString false """
let c =
builder
.CaptureStartupErrors(true)
.UseSerilog(dispose = true)
.UseStartup<Startup>()
""" config
|> prepend newline
|> should equal """
let c =
builder
.CaptureStartupErrors(true)
.UseSerilog(dispose = true)
.UseStartup<Startup>()
"""
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Version>4.1.1</Version>
<Version>4.2.0-alpha-001</Version>
<NoWarn>FS0988</NoWarn>
<TargetFramework>netcoreapp3.1</TargetFramework>
<WarningsAsErrors>FS0025</WarningsAsErrors>
Expand Down
5 changes: 4 additions & 1 deletion src/Fantomas.Tests/FunctionDefinitionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -539,7 +539,10 @@ let private addTaskToScheduler (scheduler: IScheduler)
jobDataMap.["task"] <- task
let job =
JobBuilder.Create<WrapperJob>().UsingJobData(jobDataMap).WithIdentity(taskName, groupName)
JobBuilder
.Create<WrapperJob>()
.UsingJobData(jobDataMap)
.WithIdentity(taskName, groupName)
.Build()
1
Expand Down
8 changes: 5 additions & 3 deletions src/Fantomas.Tests/LambdaTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -253,9 +253,11 @@ CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettin
|> should equal """
CloudStorageAccount.SetConfigurationSettingPublisher(fun configName configSettingPublisher ->
let connectionString =
if hostedService
then RoleEnvironment.GetConfigurationSettingValue(configName)
else ConfigurationManager.ConnectionStrings.[configName].ConnectionString
if hostedService then
RoleEnvironment.GetConfigurationSettingValue(configName)
else
ConfigurationManager.ConnectionStrings.[configName]
.ConnectionString
configSettingPublisher.Invoke(connectionString)
|> ignore)
Expand Down
13 changes: 10 additions & 3 deletions src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,9 @@ let tomorrow =
MaxValueBindingWidth = 70 })
|> prepend newline
|> should equal """
let tomorrow = DateTimeOffset(n.Year, n.Month, n.Day, 0, 0, 0, n.Offset).AddDays(1.)
let tomorrow =
DateTimeOffset(n.Year, n.Month, n.Day, 0, 0, 0, n.Offset)
.AddDays(1.)
"""

[<Test>]
Expand Down Expand Up @@ -721,7 +723,11 @@ let private authenticateRequest (logger: ILogger) header =
try
task {
let! config = manager.GetConfigurationAsync().ConfigureAwait(false)
let! config =
manager
.GetConfigurationAsync()
.ConfigureAwait(false)
parameters.IssuerSigningKeys <- config.SigningKeys
let user, _ =
Expand Down Expand Up @@ -874,7 +880,8 @@ let ``don't add additional newline before SynExpr.New, 1049`` () =
let getVersion () =
let version =
let assembly =
typeof<FSharp.Compiler.SourceCodeServices.FSharpChecker>.Assembly
typeof<FSharp.Compiler.SourceCodeServices.FSharpChecker>
.Assembly
let version = assembly.GetName().Version
sprintf "%i.%i.%i" version.Major version.Minor version.Revision
Expand Down
Loading

0 comments on commit 6eb91d8

Please sign in to comment.