diff --git a/src/Fantomas.Tests/KeepIndentInBranchTests.fs b/src/Fantomas.Tests/KeepIndentInBranchTests.fs index fcf46552f1..deff49ea3f 100644 --- a/src/Fantomas.Tests/KeepIndentInBranchTests.fs +++ b/src/Fantomas.Tests/KeepIndentInBranchTests.fs @@ -2045,3 +2045,43 @@ module Foo = { Hi = blah } |> Ok """ + +[] +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 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index d11fc4413e..4485c25bcb 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -5350,6 +5350,7 @@ and genKeepIdentIf let long = ifElse (idx = 0) (!- "if ") (!- "elif ") +> genExprInIfOrMatch astContext ifExpr + +> sepSpace +> !- "then" expressionFitsOnRestOfLine short long