From 815fec021c38a5c230a7eb955e6fc9d7b8ac2554 Mon Sep 17 00:00:00 2001 From: nojaf Date: Tue, 22 Dec 2020 21:55:12 +0100 Subject: [PATCH] Put comma upfront when SynExpr.IfThenElse is inside Tuple. Fixes #1319. --- src/Fantomas.Tests/TupleTests.fs | 30 ++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 5 +++-- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/src/Fantomas.Tests/TupleTests.fs b/src/Fantomas.Tests/TupleTests.fs index 7e5c3132d8..91e989b205 100644 --- a/src/Fantomas.Tests/TupleTests.fs +++ b/src/Fantomas.Tests/TupleTests.fs @@ -238,3 +238,33 @@ let (var1withAVeryLongLongLongLongLongLongName, var2withAVeryLongLongLongLongLongLongName) = // foo someFunc 1, someFunc 2 """ + +[] +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 +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 06ddfa75c9..07e3fe3fe1 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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)