Skip to content

Commit

Permalink
Put comma upfront when SynExpr.IfThenElse is inside Tuple. Fixes fspr…
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Dec 22, 2020
1 parent f0e431e commit 815fec0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 2 deletions.
30 changes: 30 additions & 0 deletions src/Fantomas.Tests/TupleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -238,3 +238,33 @@ let (var1withAVeryLongLongLongLongLongLongName,
var2withAVeryLongLongLongLongLongLongName) = // foo
someFunc 1, someFunc 2
"""

[<Test>]
let ``tuple with if/then/else, 1319`` () =
formatSourceString
false
"""
let y =
if String.IsNullOrWhiteSpace(args) then ""
elif args.StartsWith("(") then args
elif v.CurriedParameterGroups.Count > 1 && (not verboseMode) then " " + args
else sprintf "(%s)" args
, namesWithIndices
"""
config
|> prepend newline
|> should
equal
"""
let y =
if String.IsNullOrWhiteSpace(args) then
""
elif args.StartsWith("(") then
args
elif v.CurriedParameterGroups.Count > 1
&& (not verboseMode) then
" " + args
else
sprintf "(%s)" args
, namesWithIndices
"""
5 changes: 3 additions & 2 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1151,18 +1151,19 @@ and genTuple astContext es =
col sepComma es (genShortExpr astContext)

let longExpression =
let containsLambdaOrMatchExpr =
let shouldAddCommaUpFront =
es
|> List.pairwise
|> List.exists
(function
| SynExpr.Match _, _
| SynExpr.Lambda _, _
| SynExpr.IfThenElse _, _
| InfixApp (_, _, _, SynExpr.Lambda _), _ -> true
| _ -> false)

let sep =
if containsLambdaOrMatchExpr then
if shouldAddCommaUpFront then
(sepNln +> sepComma)
else
(sepComma +> sepNln)
Expand Down

0 comments on commit 815fec0

Please sign in to comment.