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

Feature BlankLinesAroundNestedMultilineExpressions #1587

Merged
merged 3 commits into from
Apr 5, 2021
Merged
Changes from 1 commit
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
Prev Previous commit
Rename setting to BlankLinesAroundNestedMultilineExpressions and add …
…documentation.
nojaf committed Apr 5, 2021
commit cca4e5e05fe09904963ab187be6056084bb7c56d
43 changes: 43 additions & 0 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
@@ -93,6 +93,7 @@ fsharp_alternative_long_member_definitions=false
fsharp_multi_line_lambda_closing_newline=false
fsharp_disable_elmish_syntax=false
fsharp_keep_indent_in_branch=false
fsharp_blank_lines_around_nested_multiline_expressions=true
fsharp_strict_mode=false
```

@@ -1060,6 +1061,48 @@ let main argv =
0
```

### fsharp_blank_lines_around_nested_multiline_expressions

Surround **nested** multi-line expressions with blank lines.
Existing blank lines are always preserved (via trivia).
Top level expressions will always follow the [2020 blank lines revision](https://github.com/fsprojects/fantomas/blob/master/docs/FormattingConventions.md#2020-revision) principle.
Default = true.

`defaultConfig`

```fsharp
let topLevelFunction () =
printfn "Something to print"
try
nothing ()
with
| ex ->
splash ()
()
let secondTopLevelFunction () =
// ...
()
```

`{ defaultConfig with BlankLinesAroundNestedMultilineExpressions = false }`

```fsharp
let topLevelFunction () =
printfn "Something to print"
try
nothing ()
with
| ex ->
splash ()
()
let secondTopLevelFunction () =
// ...
()
```

### fsharp_strict_mode

If being set, pretty printing is only done via ASTs. Compiler directives, inline comments and block comments will be ignored.
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module Fantomas.Tests.NewlinesAroundInnerMultilineExpressions
module Fantomas.Tests.BlankLinesAroundNestedMultilineExpressions

open NUnit.Framework
open FsUnit
open Fantomas.Tests.TestHelper

let config =
{ config with
NewlinesAroundInnerMultilineExpressions = false }
BlankLinesAroundNestedMultilineExpressions = false }

[<Test>]
let ``basic behavior`` () =
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/Fantomas.Tests.fsproj
Original file line number Diff line number Diff line change
@@ -85,7 +85,7 @@
<Compile Include="DotIndexedSetTests.fs" />
<Compile Include="MultilineFunctionApplicationsInConditionExpressionsTests.fs" />
<Compile Include="KeepIndentInBranch.fs" />
<Compile Include="NewlinesAroundInnerMultilineExpressions.fs" />
<Compile Include="BlankLinesAroundNestedMultilineExpressions.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Extras\Fantomas.Extras.fsproj" />
2 changes: 1 addition & 1 deletion src/Fantomas.Tests/KeepIndentInBranch.fs
Original file line number Diff line number Diff line change
@@ -883,7 +883,7 @@ module Foo =
0
"""
{ config with
NewlinesAroundInnerMultilineExpressions = false }
BlankLinesAroundNestedMultilineExpressions = false }
|> prepend newline
|> should
equal
2 changes: 1 addition & 1 deletion src/Fantomas/Context.fs
Original file line number Diff line number Diff line change
@@ -1508,7 +1508,7 @@ let internal colWithNlnWhenItemIsMultiline (items: ColMultilineItem list) =
impl items

let internal colWithNlnWhenItemIsMultilineUsingConfig (items: ColMultilineItem list) (ctx: Context) =
if ctx.Config.NewlinesAroundInnerMultilineExpressions then
if ctx.Config.BlankLinesAroundNestedMultilineExpressions then
colWithNlnWhenItemIsMultiline items ctx
else
col sepNln items (fun (ColMultilineItem (expr, _, _)) -> expr) ctx
4 changes: 2 additions & 2 deletions src/Fantomas/FormatConfig.fs
Original file line number Diff line number Diff line change
@@ -94,7 +94,7 @@ type FormatConfig =
DisableElmishSyntax: bool
EndOfLine: EndOfLineStyle
KeepIndentInBranch: bool
NewlinesAroundInnerMultilineExpressions: bool
BlankLinesAroundNestedMultilineExpressions: bool
/// Pretty printing based on ASTs only
StrictMode: bool }

@@ -135,5 +135,5 @@ type FormatConfig =
DisableElmishSyntax = false
EndOfLine = EndOfLineStyle.FromEnvironment
KeepIndentInBranch = false
NewlinesAroundInnerMultilineExpressions = true
BlankLinesAroundNestedMultilineExpressions = true
StrictMode = false }