Skip to content

Commit

Permalink
Don't indent and add newline when multiline Feliz expression has no c…
Browse files Browse the repository at this point in the history
…hildren. Fixes fsprojects#1510.
  • Loading branch information
nojaf committed Mar 8, 2021
1 parent f828c65 commit 8fe4e3a
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
34 changes: 34 additions & 0 deletions src/Fantomas.Tests/ElmishTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1290,3 +1290,37 @@ let html =
(* meh *)
] ] ] ]
"""

[<Test>]
let ``empty single list long expression, 1510`` () =
formatSourceString
false
"""
[<ReactComponent>]
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
"""
[<ReactComponent>]
let Dashboard () =
Html.div [
Html.div []
Html.div [
Html.text "hola muy buenas"
]
]
"""
7 changes: 4 additions & 3 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down

0 comments on commit 8fe4e3a

Please sign in to comment.