Skip to content

Commit

Permalink
fix misindentation of elif condition expression (#544)
Browse files Browse the repository at this point in the history
  • Loading branch information
smoothdeveloper authored and jindraivanek committed Oct 29, 2019
1 parent 676e9b1 commit 83d814d
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
6 changes: 3 additions & 3 deletions src/Fantomas.Tests/CommentTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
29 changes: 28 additions & 1 deletion src/Fantomas.Tests/ControlStructureTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -414,4 +414,31 @@ for _ in 1..10 do ()
|> should equal """
for _ in 1 .. 10 do
()
"""
"""

[<Test>]
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<obj> 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<obj> then
Some ex
else
None
"""
6 changes: 4 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
)
Expand Down

0 comments on commit 83d814d

Please sign in to comment.