Skip to content

Commit

Permalink
Initial support of setting KeepIndentInBranch. (#1502)
Browse files Browse the repository at this point in the history
* Initial support of setting KeepIndentInBranch.

* Start KeepIndentInBranch feature from the SynBinding level.

* Add documentation for fsharp_keep_indent_in_branch.

* Format KeepIndentInBranch.fs

* Always add newline before else expression or last clause body.

* Only not indent if setting is enabled.

* Bump version to 4.5.0-alpha-002.
  • Loading branch information
nojaf authored Mar 22, 2021
1 parent f79dfe5 commit 8eec950
Show file tree
Hide file tree
Showing 14 changed files with 958 additions and 129 deletions.
17 changes: 17 additions & 0 deletions RELEASE_NOTES.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,20 @@
### 4.5.0-alpha-002 - 03/2021

* Initial support of KeepIndentInBranch. [#1361](https://github.com/fsprojects/fantomas/issues/1361)
* Improve: Collect empty define block as single trivia. [#1528](https://github.com/fsprojects/fantomas/pull/1528)
* Improve: Refactor ASTTransformer. [#1497](https://github.com/fsprojects/fantomas/pull/1497)
* Improve: replace genTypeByLookup with Trivia. [#594](https://github.com/fsprojects/fantomas/issues/594)
* Fix DotGet infix expression. [#1529](https://github.com/fsprojects/fantomas/issues/1529)
* Fix SynPat.Or should have the same indent. [#1522](https://github.com/fsprojects/fantomas/issues/1522)
* Fix DotGet with parenthesis. [#1521](https://github.com/fsprojects/fantomas/issues/1521)
* Fix Trivia regressions around SynConst. [#1518](https://github.com/fsprojects/fantomas/issues/1518)
* Fix Long signatures have additonal newline inserted and don't respect the indent from the config. [#1515](https://github.com/fsprojects/fantomas/issues/1515)
* Fix Bad formatting when using elmish style + empty arrays. [#1510](https://github.com/fsprojects/fantomas/issues/1510)
* Fix \xHH escapes in string literal are expanded. [#1508](https://github.com/fsprojects/fantomas/issues/1508)
* Fix Indentation of pattern match clause. [#1501](https://github.com/fsprojects/fantomas/issues/1501)
* Fix Class parameters expands unit for long lines. [#1494](https://github.com/fsprojects/fantomas/issues/1494)
* Fix Comments inside Elmish gets repeated. [#1347](https://github.com/fsprojects/fantomas/issues/1347)

### 4.5.0-alpha-001 - 02/2021

* Update to FCS 39 [#1479](https://github.com/fsprojects/fantomas/pull/1479)
Expand Down
44 changes: 43 additions & 1 deletion docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ The output path is prompted by `--out` e.g.

Both paths have to be files or folders at the same time.
If they are folders, the structure of input folder will be reflected in the output one.
The tool will explore the input folder recursively if you set `--recurse` option (see [Options section](#options)).
The tool will explore the input folder recursively if you set `--recurse` option.
If you omit the output path, Fantomas will overwrite the input files.

## Configuration
Expand Down Expand Up @@ -92,6 +92,7 @@ fsharp_align_function_signature_to_indentation=false
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_strict_mode=false
```

Expand Down Expand Up @@ -1018,6 +1019,47 @@ let encodeUrlModel code model: JsonValue =
"code", Encode.string code ]
```

### fsharp_keep_indent_in_branch

Breaks the normal indentation flow for the last branch of a pattern match of if/then/else expression.
Only when the pattern match or if/then/else is the return value of a function or member.

`defaultConfig`

```fsharp
let main argv =
let args = parse argv
let instructions = Library.foo args
if args.DryRun = RunMode.Dry then
printfn "Would execute actions, but --dry-run was supplied: %+A" instructions
0
else
// proceed with main method
let output = Library.execute instructions
// do more stuff
0
```

`{ defaultConfig with KeepIndentInBranch = true }`

```fsharp
let main argv =
let args = parse argv
let instructions = Library.foo args
if args.DryRun = RunMode.Dry then
printfn "Would execute actions, but --dry-run was supplied: %+A" instructions
0
else
// proceed with main method
let output = Library.execute instructions
// do more stuff
0
```

### fsharp_strict_mode

If being set, pretty printing is only done via ASTs. Compiler directives, inline comments and block comments will be ignored.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<TargetFramework>net5.0</TargetFramework>
<IsPackable>false</IsPackable>
<GenerateProgramFile>false</GenerateProgramFile>
<Version>4.5.0-alpha-001</Version>
<Version>4.5.0-alpha-002</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 @@ -5,7 +5,7 @@
<RollForward>Major</RollForward>
<ToolCommandName>fantomas</ToolCommandName>
<PackAsTool>True</PackAsTool>
<Version>4.5.0-alpha-001</Version>
<Version>4.5.0-alpha-002</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.5.0-alpha-001</Version>
<Version>4.5.0-alpha-002</Version>
<Description>Utility package for Fantomas</Description>
<WarningsAsErrors>FS0025</WarningsAsErrors>
</PropertyGroup>
Expand Down
3 changes: 2 additions & 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.5.0-alpha-001</Version>
<Version>4.5.0-alpha-002</Version>
<NoWarn>FS0988</NoWarn>
<TargetFramework>net5.0</TargetFramework>
<WarningsAsErrors>FS0025</WarningsAsErrors>
Expand Down Expand Up @@ -84,6 +84,7 @@
<Compile Include="DotIndexedGetTests.fs" />
<Compile Include="DotIndexedSetTests.fs" />
<Compile Include="MultilineFunctionApplicationsInConditionExpressionsTests.fs" />
<Compile Include="KeepIndentInBranch.fs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Fantomas.Extras\Fantomas.Extras.fsproj" />
Expand Down
20 changes: 19 additions & 1 deletion src/Fantomas.Tests/FormatConfigEditorConfigurationFileTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ open Fantomas
open Fantomas.FormatConfig
open Fantomas.Extras
open Fantomas.Tests.TestHelper
open FsUnit
open NUnit.Framework
open System.IO

Expand Down Expand Up @@ -431,3 +430,22 @@ fsharp_multi_line_lambda_closing_newline = true
EditorConfig.readConfiguration fsharpFile.FSharpFile

Assert.IsTrue config.MultiLineLambdaClosingNewline

[<Test>]
let fsharp_keep_indent_in_branch () =
let rootDir = tempName ()

let editorConfig = """
[*.fs]
fsharp_keep_indent_in_branch = true
"""

use configFixture =
new ConfigurationFile(defaultConfig, rootDir, content = editorConfig)

use fsharpFile = new FSharpFile(rootDir)

let config =
EditorConfig.readConfiguration fsharpFile.FSharpFile

Assert.IsTrue config.KeepIndentInBranch
Loading

0 comments on commit 8eec950

Please sign in to comment.