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 )