Skip to content

Commit

Permalink
Fix parenthesis placement with Stroustrup alignment when using MultiL…
Browse files Browse the repository at this point in the history
…ineLambdaClosingNewline=true (#2714)

* Fix paren placement with Stroustrup alignment

* Ensure expression is stroustrup when dropping the newline.

Co-authored-by: Florian Verdonck <[email protected]>
  • Loading branch information
josh-degraw and nojaf authored Jan 14, 2023
1 parent b5129e4 commit 5336c50
Show file tree
Hide file tree
Showing 3 changed files with 179 additions and 55 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# Changelog

## [Unreleased]
## [5.2.0-alpha-012] - 2023-01-14

### Fixed
* Trivia before open statement is not preserved. [#2704](https://github.com/fsprojects/fantomas/issues/2704)
* Type app identifier is considered as an expression. [#2705](https://github.com/fsprojects/fantomas/issues/2705)
* Subsequent identifier links in chain should be on the same line. [#2712](https://github.com/fsprojects/fantomas/issues/2712)
* Delegate with many parameters result in a compilation error. [#1514](https://github.com/fsprojects/fantomas/issues/1514)
* MultiLineLambdaClosingNewline + ExperimentalStroustrupStyle is not displaying very well for some use cases. [#2378](https://github.com/fsprojects/fantomas/issues/2378)

## [5.2.0-alpha-011] - 2023-01-12

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ let config =
MultilineBracketStyle = ExperimentalStroustrup
MaxArrayOrListWidth = 40 }

// TODO: figure out what should happen when you mix MultiLineLambdaClosingNewline and Stroustrup
// From a technical point of view, this is correct behavior but having `})` at the end seems sensible as well.

[<Test>]
let ``paren lambda with record instance`` () =
formatSourceString
Expand All @@ -33,8 +30,7 @@ let ``paren lambda with record instance`` () =
A = longTypeName
B = someOtherVariable
C = ziggyBarX
}
)
})
"""

[<Test>]
Expand Down Expand Up @@ -76,8 +72,7 @@ let ``paren lambda with anonymous record instance`` () =
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
"""

[<Test>]
Expand All @@ -100,8 +95,7 @@ let ``paren lambda with anonymous record instance struct`` () =
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
"""

[<Test>]
Expand All @@ -123,8 +117,7 @@ let ``paren lambda with computation expression`` () =
(fun x -> task {
// some computation here
()
}
)
})
"""

[<Test>]
Expand All @@ -150,8 +143,7 @@ let ``paren lambda with list`` () =
itemThree
itemFour
itemFive
]
)
])
"""

[<Test>]
Expand All @@ -177,8 +169,7 @@ let ``paren lambda with array`` () =
itemThree
itemFour
itemFive
|]
)
|])
"""

[<Test>]
Expand All @@ -200,8 +191,7 @@ List.map (fun x -> {
A = longTypeName
B = someOtherVariable
C = ziggyBarX
}
)
})
"""

[<Test>]
Expand Down Expand Up @@ -243,8 +233,7 @@ List.map (fun x -> {|
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
"""

[<Test>]
Expand All @@ -267,8 +256,7 @@ List.map (fun x -> struct {|
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
"""

[<Test>]
Expand All @@ -290,8 +278,7 @@ List.map (fun x ->
List.map (fun x -> task {
// some computation here
()
}
)
})
"""

[<Test>]
Expand All @@ -317,8 +304,7 @@ List.map (fun x -> [
itemThree
itemFour
itemFive
]
)
])
"""

[<Test>]
Expand All @@ -344,8 +330,7 @@ List.map (fun x -> [|
itemThree
itemFour
itemFive
|]
)
|])
"""

[<Test>]
Expand All @@ -368,8 +353,7 @@ List.map
A = longTypeName
B = someOtherVariable
C = ziggyBarX
}
)
})
b
c
"""
Expand Down Expand Up @@ -417,8 +401,7 @@ List.map
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
b
c
"""
Expand All @@ -444,8 +427,7 @@ List.map
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
b
c
"""
Expand All @@ -470,8 +452,7 @@ List.map
(fun x -> task {
// some computation here
()
}
)
})
b
c
"""
Expand Down Expand Up @@ -500,8 +481,7 @@ List.map
itemThree
itemFour
itemFive
]
)
])
b
c
"""
Expand Down Expand Up @@ -530,8 +510,7 @@ List.map
itemThree
itemFour
itemFive
|]
)
|])
b
c
"""
Expand All @@ -557,8 +536,7 @@ Bar
B = someOtherVariable
C = ziggyBarX
D = evenMoreZigBarry
}
)
})
.Bar()
"""

Expand Down Expand Up @@ -610,8 +588,7 @@ Bar
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
.Bar()
"""

Expand All @@ -637,8 +614,7 @@ Bar
A = longTypeName
B = someOtherVariable
C = ziggyBarX
|}
)
|})
.Bar()
"""

Expand All @@ -663,8 +639,7 @@ Bar
.Foo(fun x -> task {
// some computation here
()
}
)
})
.Bar()
"""

Expand Down Expand Up @@ -693,8 +668,7 @@ Bar
itemThree
itemFour
itemFive
]
)
])
.Bar()
"""

Expand Down Expand Up @@ -723,7 +697,133 @@ Bar
itemThree
itemFour
itemFive
|]
|])
.Bar()
"""

[<Test>]
let ``non stroustrup expression lambda body expression stills adds newline`` () =
formatSourceString
false
"""
List.map (fun e ->
try
f e
with
| ex -> "meh")
"""
config
|> prepend newline
|> should
equal
"""
List.map (fun e ->
try
f e
with ex ->
"meh"
)
"""

[<Test>]
let ``non stroustrup expression lambda body expression stills adds newline, multiple arguments in function application``
()
=
formatSourceString
false
"""
fn a b c (fun e ->
try
f e
with
| ex -> "meh")
"""
config
|> prepend newline
|> should
equal
"""
fn
a
b
c
(fun e ->
try
f e
with ex ->
"meh"
)
"""

[<Test>]
let ``application with match lambda should not be affected by stroustrup`` () =
formatSourceString
false
"""
List.map (function
| X x -> ()
| Y y -> ())
"""
config
|> prepend newline
|> should
equal
"""
List.map (
function
| X x -> ()
| Y y -> ()
)
"""

[<Test>]
let ``non stroustrup argument in application in chain`` () =
formatSourceString
false
"""
Foo.Bar().Meh(fun m ->
try
f e
with ex ->
"meh"
)
"""
config
|> prepend newline
|> should
equal
"""
Foo
.Bar()
.Meh(fun m ->
try
f e
with ex ->
"meh"
)
"""

[<Test>]
let ``non stroustrup body in paren lambda`` () =
formatSourceString
false
"""
(fun m ->
try
f e
with ex ->
"meh"
)
"""
config
|> prepend newline
|> should
equal
"""
(fun m ->
try
f e
with ex ->
"meh"
)
"""
Loading

0 comments on commit 5336c50

Please sign in to comment.