diff --git a/src/Fantomas.Tests/IfThenElseTests.fs b/src/Fantomas.Tests/IfThenElseTests.fs index 6b96556151..9f80968cc1 100644 --- a/src/Fantomas.Tests/IfThenElseTests.fs +++ b/src/Fantomas.Tests/IfThenElseTests.fs @@ -2085,3 +2085,40 @@ then else () """ + +[] +let ``multiline infix expression in if expression, 1584`` () = + formatSourceString + false + """ + if sourceCode.EndsWith("\n") + && not + <| formattedSourceCode.EndsWith(Environment.NewLine) then + return formattedSourceCode + Environment.NewLine + elif + not <| sourceCode.EndsWith("\n") + && formattedSourceCode.EndsWith(Environment.NewLine) + then + return formattedSourceCode.TrimEnd('\r', '\n') + else + return formattedSourceCode +""" + config + |> prepend newline + |> should + equal + """ +if + sourceCode.EndsWith("\n") + && not + <| formattedSourceCode.EndsWith(Environment.NewLine) +then + return formattedSourceCode + Environment.NewLine +elif + not <| sourceCode.EndsWith("\n") + && formattedSourceCode.EndsWith(Environment.NewLine) +then + return formattedSourceCode.TrimEnd('\r', '\n') +else + return formattedSourceCode +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index b7edbc697f..d6cdc43c85 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2269,7 +2269,7 @@ and genExpr astContext synExpr ctx = indent +> sepNln +> genAlternativeAppWithParenthesis app astContext - +> sepSpace + +> ifElse (noBreakInfixOps.Contains(s)) sepSpace sepNln +> genInfixOperator s e +> sepSpace +> genExpr astContext e2