From 90fe9a00db60686794f1c079069d2159d326b352 Mon Sep 17 00:00:00 2001 From: nojaf Date: Sat, 3 Apr 2021 16:31:30 +0200 Subject: [PATCH] Add newline between multiline infix expression in if expression. Fixes #1584. --- src/Fantomas.Tests/IfThenElseTests.fs | 37 +++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 2 +- 2 files changed, 38 insertions(+), 1 deletion(-) 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