Skip to content

Commit

Permalink
Add brace before indentation. Fixes fsprojects#835
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 15, 2020
1 parent 622e2b0 commit 96c166b
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 5 deletions.
48 changes: 48 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -277,3 +277,51 @@ let tests =
let tests =
testList "tests" [ test "test" { Expect.equal true true "unexpected" } ]
"""

[<Test>]
let ``multiline computation expression with SynExpr.App identifier, 835`` () =
formatSourceString false """let meh =
create [] {
// foo
// bar
return 42
}""" config
|> prepend newline
|> should equal """
let meh =
create [] {
// foo
// bar
return 42
}
"""

[<Test>]
let ``multiline computation expression with SynExpr.App identifier and multiple expressions`` () =
formatSourceString false """
let private validateLocation =
createValidatorFor<LocationAdded> () {
validate (fun l -> l.Id) [ isNotEmptyGuid ]
validate (fun l -> l.Name)
[ isNotEmpty
hasMinLengthOf 3 ]
validate (fun l -> fst l.Location) [ isValidLatitude ]
validate (fun l -> snd l.Location) [ isValidLongitude ]
validate (fun l -> l.Price) [ isGreaterThan 0. ]
validate (fun l -> l.Date) [ isNotMinDate ]
validate (fun l -> l.Creator) [ isNotEmpty ]
}
""" config
|> prepend newline
|> should equal """
let private validateLocation =
createValidatorFor<LocationAdded> () {
validate (fun l -> l.Id) [ isNotEmptyGuid ]
validate (fun l -> l.Name) [ isNotEmpty; hasMinLengthOf 3 ]
validate (fun l -> fst l.Location) [ isValidLatitude ]
validate (fun l -> snd l.Location) [ isValidLongitude ]
validate (fun l -> l.Price) [ isGreaterThan 0. ]
validate (fun l -> l.Date) [ isNotMinDate ]
validate (fun l -> l.Creator) [ isNotEmpty ]
}
"""
8 changes: 3 additions & 5 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1189,11 +1189,9 @@ and genExpr astContext synExpr =
atCurrentColumn
(genExpr astContext e
+> colPre sepSpace sepSpace es (fun e ->
indent
+> appNlnFun e
(indentIfNeeded
+> onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace)
+> genExpr astContext e)
onlyIf (isCompExpr e) (sepSpace +> sepOpenSFixed +> sepSpace)
+> indent
+> appNlnFun e (indentIfNeeded +> genExpr astContext e)
+> unindent))

| TypeApp(e, ts) -> genExpr astContext e -- "<" +> col sepComma ts (genType astContext false) -- ">"
Expand Down

0 comments on commit 96c166b

Please sign in to comment.