diff --git a/src/Fantomas.Tests/CommentTests.fs b/src/Fantomas.Tests/CommentTests.fs index f73c645a3d..e2cd8beab0 100644 --- a/src/Fantomas.Tests/CommentTests.fs +++ b/src/Fantomas.Tests/CommentTests.fs @@ -646,9 +646,9 @@ type substring = if strA.Length = 0 && strB.Length = 0 then 0 elif - // OPTIMIZATION : If the substrings have the same (identical) underlying string - // and offset, the comparison value will depend only on the length of the substrings. - strA.String == strB.String && strA.Offset = strB.Offset then compare strA.Length strB.Length + // OPTIMIZATION : If the substrings have the same (identical) underlying string + // and offset, the comparison value will depend only on the length of the substrings. + strA.String == strB.String && strA.Offset = strB.Offset then compare strA.Length strB.Length else (* Structural comparison on substrings -- this uses the same comparison diff --git a/src/Fantomas.Tests/ControlStructureTests.fs b/src/Fantomas.Tests/ControlStructureTests.fs index 0ac035d2ff..5514b9d664 100644 --- a/src/Fantomas.Tests/ControlStructureTests.fs +++ b/src/Fantomas.Tests/ControlStructureTests.fs @@ -414,4 +414,31 @@ for _ in 1..10 do () |> should equal """ for _ in 1 .. 10 do () -""" \ No newline at end of file +""" + +[] +let ``if elif if with trivia doesn't glitch elif conditional`` () = + formatSourceString false """ +let a ex = + if null = ex then + fooo () + None + // this was None + elif ex.GetType() = typeof then + Some ex + else + None +""" config + |> prepend newline + |> should equal """ +let a ex = + if null = ex then + fooo() + None + elif + // this was None + ex.GetType() = typeof then + Some ex + else + None +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 4a8e3abbf5..ac6a937c10 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1158,10 +1158,12 @@ and genExpr astContext synExpr = ) "if " elsePart +> - genTrivia node.Range (ifElse (checkBreakForExpr e1) + indent +> (genTrivia node.Range ( + (ifElse (checkBreakForExpr e1) (genExpr astContext e1 +> thenToken node.Range !+"then") (genExpr astContext e1 +> thenToken node.Range !+-"then") - -- " " +> printBranch id astContext e2) + -- " " +> unindent +> printBranch id astContext e2) + )) ) ctx +> opt sepNone enOpt (fun en -> printBranch (elseToken fullRange !+~"else ") astContext en) )