Skip to content

Commit

Permalink
Add space after long if expression in KeepIndentInBranch. Fixes fspro…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Jul 6, 2021
1 parent 7cde65d commit add0d68
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
40 changes: 40 additions & 0 deletions src/Fantomas.Tests/KeepIndentInBranchTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2045,3 +2045,43 @@ module Foo =
{ Hi = blah } |> Ok
"""

[<Test>]
let ``add space after long identifier in if expression, 1816`` () =
formatSourceString
false
"""
module Foo =
let assertConsistent () : unit =
if veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong then
()
else
if foo = bar then
()
else
let leftSet = HashSet (FooBarBaz.keys leftThings)
leftSet.SymmetricExceptWith (FooBarBaz.keys rightThings)
|> ignore
"""
{ config with
MaxLineLength = 100
MultilineBlockBracketsOnSameColumn = true
MultiLineLambdaClosingNewline = true
KeepIndentInBranch = true }
|> prepend newline
|> should
equal
"""
module Foo =
let assertConsistent () : unit =
if veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLong then
()
elif foo = bar then
()
else
let leftSet = HashSet(FooBarBaz.keys leftThings)
leftSet.SymmetricExceptWith(FooBarBaz.keys rightThings)
|> ignore
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -5350,6 +5350,7 @@ and genKeepIdentIf
let long =
ifElse (idx = 0) (!- "if ") (!- "elif ")
+> genExprInIfOrMatch astContext ifExpr
+> sepSpace
+> !- "then"

expressionFitsOnRestOfLine short long
Expand Down

0 comments on commit add0d68

Please sign in to comment.