diff --git a/src/Fantomas.Tests/DynamicOperatorTests.fs b/src/Fantomas.Tests/DynamicOperatorTests.fs index 40433b0ef6..51c1808e60 100644 --- a/src/Fantomas.Tests/DynamicOperatorTests.fs +++ b/src/Fantomas.Tests/DynamicOperatorTests.fs @@ -37,10 +37,10 @@ let ``keep () when dynamic operator inside boolean expr, #476`` () = equal """ let fieldColor (fieldNameX: string) = - if f.errors?(fieldNameY) && f.touched?(fieldNameZ) then - IsDanger - else - NoColor + (if f.errors?(fieldNameY) && f.touched?(fieldNameZ) then + IsDanger + else + NoColor) |> Input.Color """ diff --git a/src/Fantomas.Tests/IfThenElseTests.fs b/src/Fantomas.Tests/IfThenElseTests.fs index d61fe70edc..0041e3de56 100644 --- a/src/Fantomas.Tests/IfThenElseTests.fs +++ b/src/Fantomas.Tests/IfThenElseTests.fs @@ -1658,3 +1658,35 @@ let tryDecompile (ty: FSharpEntity) = |> tryGetSource } """ + +[] +let ``if then else followed by pipe, 1327`` () = + formatSourceString + false + """ +module X = + let getValSignature displayContext (v: FSharpMemberOrFunctionOrValue) = + let name = + if v.DisplayName.StartsWith "( " + then v.LogicalName + else v.DisplayName + |> PrettyNaming.QuoteIdentifierIfNeeded + + () +""" + { config with IndentSize = 2 } + |> prepend newline + |> should + equal + """ +module X = + let getValSignature displayContext (v: FSharpMemberOrFunctionOrValue) = + let name = + (if v.DisplayName.StartsWith "( " then + v.LogicalName + else + v.DisplayName) + |> PrettyNaming.QuoteIdentifierIfNeeded + + () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index fed70b42a6..9e0fff85b5 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -2769,8 +2769,13 @@ and genMultilineInfixExpr astContext e1 operatorText operatorExpr e2 = if noBreakInfixOps.Contains(operatorText) then genOnelinerInfixExpr astContext e1 operatorText operatorExpr e2 else + let genE1 = + match e1 with + | SynExpr.IfThenElse _ -> autoParenthesisIfExpressionExceedsPageWidth (genExpr astContext e1) + | _ -> genExpr astContext e1 + atCurrentColumn ( - genExpr astContext e1 + genE1 +> sepNln +> genInfixOperator operatorText operatorExpr +> sepSpace