From 8fe4e3ab2614cce6f932360c717703d4f4857a1f Mon Sep 17 00:00:00 2001 From: nojaf Date: Mon, 8 Mar 2021 20:06:59 +0100 Subject: [PATCH] Don't indent and add newline when multiline Feliz expression has no children. Fixes #1510. --- src/Fantomas.Tests/ElmishTests.fs | 34 +++++++++++++++++++++++++++++++ src/Fantomas/CodePrinter.fs | 7 ++++--- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/src/Fantomas.Tests/ElmishTests.fs b/src/Fantomas.Tests/ElmishTests.fs index b5ce9455c1..e8c1c7cdaa 100644 --- a/src/Fantomas.Tests/ElmishTests.fs +++ b/src/Fantomas.Tests/ElmishTests.fs @@ -1290,3 +1290,37 @@ let html = (* meh *) ] ] ] ] """ + +[] +let ``empty single list long expression, 1510`` () = + formatSourceString + false + """ +[] +let Dashboard () = + Html.div [ + Html.div [] + Html.div [ + Html.text "hola muy buenas" + ] + ] +""" + { config with + RecordMultilineFormatter = Fantomas.FormatConfig.MultilineFormatterType.NumberOfItems + MaxArrayOrListWidth = 20 + MaxElmishWidth = 10 + SingleArgumentWebMode = true + MultiLineLambdaClosingNewline = true } + |> prepend newline + |> should + equal + """ +[] +let Dashboard () = + Html.div [ + Html.div [] + Html.div [ + Html.text "hola muy buenas" + ] + ] +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index 43cb8532a7..22805dad6f 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -1090,17 +1090,18 @@ and genExpr astContext synExpr ctx = | _ -> false) (Map.tryFindOrEmptyList closingTokenType ctx.TriviaTokenNodes) + let hasChildren = List.isNotEmpty children + atCurrentColumn ( !-identifier +> sepSpace +> tokN openingTokenRange openTokenType (ifElse isArray sepOpenAFixed sepOpenLFixed) - +> indent - +> sepNln + +> onlyIf hasChildren (indent +> sepNln) +> col sepNln children (genExpr astContext) +> onlyIf hasBlockCommentBeforeClosingToken (sepNln +> unindent) +> enterNodeTokenByName closingTokenRange closingTokenType +> onlyIfNot hasBlockCommentBeforeClosingToken unindent - +> sepNlnUnlessLastEventIsNewline + +> onlyIf hasChildren sepNlnUnlessLastEventIsNewline +> ifElse isArray sepCloseAFixed sepCloseLFixed +> leaveNodeTokenByName closingTokenRange closingTokenType )