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: Align brackets #706

Closed
wants to merge 38 commits into from
Closed
Show file tree
Hide file tree
Changes from 33 commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
4b51b00
Updated month in release notes
nojaf Feb 3, 2020
8a7c550
Merge branch 'master' of https://github.com/nojaf/fantomas
nojaf Feb 4, 2020
1363901
Re-added proposed unit tests.
nojaf Feb 4, 2020
e4f501d
Fixed simple record test
nojaf Feb 4, 2020
7ca81b7
Completely separate record implementation for now.
nojaf Feb 4, 2020
2791a8d
WIP
nojaf Feb 5, 2020
7dde3b9
Fixed nested record with bracketOnSeparateLine
nojaf Feb 5, 2020
138d32d
WIP
nojaf Feb 5, 2020
fa8a37c
Merge remote-tracking branch 'upstream/master'
nojaf Feb 6, 2020
e43c0f5
Records in lists, object expressions and record type definitions.
nojaf Feb 7, 2020
96963a7
Updated test to match latest comments from the team.
nojaf Feb 7, 2020
5e05085
WIP, call G-Research
nojaf Feb 10, 2020
2f341d8
Merge branch 'master' of https://github.com/nojaf/fantomas
nojaf Feb 18, 2020
c28a045
Merge remote-tracking branch 'upstream/master'
nojaf Feb 18, 2020
e75942e
Merge remote-tracking branch 'upstream/master'
nojaf Feb 18, 2020
3fa733c
Merge remote-tracking branch 'upstream/master'
nojaf Feb 19, 2020
dcc6b56
Merge branch 'master' into feature/bracket-on-separate-line
nojaf Feb 21, 2020
63bf52b
WIP MaxSingleLineRecordWidth
nojaf Feb 21, 2020
bc3f3a4
Merge branch 'master' into feature/bracket-on-separate-line
nojaf Feb 28, 2020
d7da612
Remove MaxSingleLineRecordWidth setting
nojaf Feb 28, 2020
71a937d
Merge remote-tracking branch 'upstream/master' into feature/bracket-o…
nojaf Feb 28, 2020
df218ef
Update test to use SpaceBeforeSemicolon setting
nojaf Feb 28, 2020
ba11699
Restore original multiline behavior for AnonRecord
nojaf Feb 28, 2020
5b64379
Minor refactor of Array/List printing
nojaf Feb 28, 2020
e03c4f9
Align brackets in Array/Lists
nojaf Feb 28, 2020
25f98de
Comment after opening bracket
nojaf Feb 28, 2020
cc37968
Working feature align brackets
nojaf Feb 28, 2020
4e5acd5
Adding documentation for AlignBrackets.
nojaf Feb 28, 2020
71d228c
Merge remote-tracking branch 'upstream/master' into feature/bracket-o…
nojaf Feb 28, 2020
40a43cd
Ignore failing test for now.
nojaf Feb 28, 2020
26cfec8
Merge branch 'master' into feature/bracket-on-separate-line
nojaf Mar 3, 2020
ee12c87
trigger ci
Mar 5, 2020
71a468d
Update Setup .NET Core
Mar 5, 2020
c430700
Merge branch 'master' into feature/bracket-on-separate-line
nojaf Mar 6, 2020
700b974
Renamed setting to MultilineBlockBracketsOnSameColumn
nojaf Mar 6, 2020
6afa4bd
Code clean up
nojaf Mar 6, 2020
63582f6
Merged master
nojaf Apr 3, 2020
1d3e55a
Type definitions members and interface examples.
nojaf Apr 3, 2020
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
3 changes: 1 addition & 2 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ jobs:
steps:
- uses: actions/checkout@v1
- name: Setup .NET Core
# Fix for https://github.com/actions/setup-dotnet/issues/29#issuecomment-548740241
uses: actions/setup-dotnet@bb95ce727fd49ec1a65933419cc7c91747785302
uses: actions/[email protected]
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Install local tools
Expand Down
3 changes: 1 addition & 2 deletions .github/workflows/myget.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ jobs:
run: echo Build number is $BUILD_NUMBER
- uses: actions/checkout@v1
- name: Setup .NET Core
# Fix for https://github.com/actions/setup-dotnet/issues/29#issuecomment-548740241
uses: actions/setup-dotnet@bb95ce727fd49ec1a65933419cc7c91747785302
uses: actions/[email protected]
with:
dotnet-version: ${{ matrix.dotnet }}
- name: Install local tools
Expand Down
60 changes: 60 additions & 0 deletions docs/Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,65 @@ That said, most of the preferences are very simple.
But they demonstrate the flexibility of Fantomas on a set of configurations.
More preferences will be added depending on use cases.

##### "AlignBrackets"

Alternative style to format records, arrays and lists.
If enabled, this will align the brackets (`{`, `{|`, `[`, `[|`) and (`}`, `|}`, `]`, `|]`) on the same line.
nojaf marked this conversation as resolved.
Show resolved Hide resolved

```fsharp
let myRecord = { Square = 9; Level = "Hard" }

let arr = [|(1, 1, 1); (1, 2, 2); (1, 3, 3); (2, 1, 2); (2, 2, 4); (2, 3, 6); (3, 1, 3);
(3, 2, 6); (3, 3, 9)|]

let anonRecord =
{| A = {| A1 = "string";A2LongerIdentifier = "foo" |};
B = {| B1 = 7 |}
C= { C1 = "foo"; C2LongerIdentifier = "bar"}
D = { D1 = "bar" } |}
```

becomes

```fsharp
let myRecord =
{
Square = 9
Level = "Hard"
}

let arr =
[|
(1, 1, 1)
(1, 2, 2)
(1, 3, 3)
(2, 1, 2)
(2, 2, 4)
(2, 3, 6)
(3, 1, 3)
(3, 2, 6)
(3, 3, 9)
|]

let anonRecord =
{|
A =
{|
A1 = "string"
A2LongerIdentifier = "foo"
|}
B = {| B1 = 7 |}
C =
{
C1 = "foo"
C2LongerIdentifier = "bar"
}
D = { D1 = "bar" }
|}
```

Only available from via `fantomas-config.json` config file.

##### `--config <Path to file or folder>`

Use a JSON configuration file based on a [schema](../src/Fantomas/schema.json) to set the formatting options.
Expand All @@ -306,6 +365,7 @@ A default configuration file would look like
"SpaceAroundDelimiter":true ,
"KeepNewlineAfter":false,
"MaxIfThenElseShortWidth":40,
"AlignBrackets": false,
nojaf marked this conversation as resolved.
Show resolved Hide resolved
"StrictMode":false
}
```
Expand Down
183 changes: 183 additions & 0 deletions src/Fantomas.Tests/AlignBracketsArrayOrListTests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,183 @@
module Fantomas.Tests.AlignBracketsArrayOrListTests

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

let config = ({ config with
AlignBrackets = true
SpaceBeforeColon = true
SpaceBeforeSemicolon = true })

[<Test>]
let ``array values``() =
formatSourceString false """
let arr = [|(1, 1, 1); (1, 2, 2); (1, 3, 3); (2, 1, 2); (2, 2, 4); (2, 3, 6); (3, 1, 3);
(3, 2, 6); (3, 3, 9)|]
""" config
|> prepend newline
|> should equal """
let arr =
[|
(1, 1, 1)
(1, 2, 2)
(1, 3, 3)
(2, 1, 2)
(2, 2, 4)
(2, 3, 6)
(3, 1, 3)
(3, 2, 6)
(3, 3, 9)
|]
"""

[<Test>]
let ``list values``() =
formatSourceString false """
let arr = [(1, 1, 1); (1, 2, 2); (1, 3, 3); (2, 1, 2); (2, 2, 4); (2, 3, 6); (3, 1, 3);
(3, 2, 6); (3, 3, 9)]
""" config
|> prepend newline
|> should equal """
let arr =
[
(1, 1, 1)
(1, 2, 2)
(1, 3, 3)
(2, 1, 2)
(2, 2, 4)
(2, 3, 6)
(3, 1, 3)
(3, 2, 6)
(3, 3, 9)
]
"""

[<Test>]
let ``short list remains on one line`` () =
formatSourceString false """let defines = ["FOO";"BAR"]""" config
|> prepend newline
|> should equal """
let defines = [ "FOO" ; "BAR" ]
"""

[<Test>]
let ``array patterns``() =
formatSourceString false """
let vectorLength vec =
match vec with
| [| var1 |] -> var1
| [| var1; var2 |] -> sqrt (var1*var1 + var2*var2)
| [| var1; var2; var3 |] -> sqrt (var1*var1 + var2*var2 + var3*var3)
| _ -> failwith "vectorLength called with an unsupported array size of %d." (vec.Length)""" config
|> prepend newline
|> should equal """
let vectorLength vec =
match vec with
| [| var1 |] -> var1
| [| var1 ; var2 |] -> sqrt (var1 * var1 + var2 * var2)
| [| var1 ; var2 ; var3 |] -> sqrt (var1 * var1 + var2 * var2 + var3 * var3)
| _ -> failwith "vectorLength called with an unsupported array size of %d." (vec.Length)
"""

[<Test; Ignore("Awaiting feedback")>]
let ``array comprehensions``() =
formatSourceString false """
let a1 = [| for i in 1 .. 10 -> i * i |]
let a2 = [| 0 .. 99 |]
let a3 = [| for n in 1 .. 100 do if isPrime n then yield n |]""" config
|> prepend newline
|> should equal """
let a1 =
[| for i in 1 .. 10 -> i * i |]

let a2 = [| 0 .. 99 |]

let a3 =
[|
for n in 1 .. 100 do
if isPrime n then yield n
|]
"""

[<Test>]
let ``line comment after opening bracket list`` () =
formatSourceString false """let a = [ // some line comment
(1,2,3); (4,5,6); (7,8,9) ]
""" config
|> prepend newline
|> should equal """
let a =
[ // some line comment
(1, 2, 3)
(4, 5, 6)
(7, 8, 9)
]
"""

[<Test>]
let ``line comment after opening bracket in short list`` () =
formatSourceString false """let a = [ // some line comment
a;b ]
let bb = b
""" config
|> prepend newline
|> should equal """
let a =
[ // some line comment
a
b
]
let bb = b
"""

[<Test>]
let ``line comment after opening bracket array`` () =
formatSourceString false """let a = [| // some line comment
(1,2,3); (4,5,6); (7,8,9) |]
""" config
|> prepend newline
|> should equal """
let a =
[| // some line comment
(1, 2, 3)
(4, 5, 6)
(7, 8, 9)
|]
"""

[<Test>]
let ``line comment before closing bracket list`` () =
formatSourceString false """let a = [
(1,2,3); (4,5,6); (7,8,9)
// some line comment
]
""" config
|> prepend newline
|> should equal """
let a =
[
(1, 2, 3)
(4, 5, 6)
(7, 8, 9)
// some line comment
]
"""

[<Test>]
let ``line comment before closing bracket array`` () =
formatSourceString false """let a = [|
(1,2,3); (4,5,6); (7,8,9)
// some line comment
|]
""" config
|> prepend newline
|> should equal """
let a =
[|
(1, 2, 3)
(4, 5, 6)
(7, 8, 9)
// some line comment
|]
"""
Loading