Skip to content

Commit

Permalink
Add brace before indentation. Fixes #835 (#836)
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed May 16, 2020
1 parent 53da9cf commit 5155008
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 7 deletions.
48 changes: 48 additions & 0 deletions src/Fantomas.Tests/ComputationExpressionTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,54 @@ 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 ]
}
"""

[<Test>]
let ``new line after multiline let bang, 819`` () =
formatSourceString false """
Expand Down
3 changes: 1 addition & 2 deletions src/Fantomas.Tests/FormatConfigJsonConfigurationFileTests.fs
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
module Fantomas.Tests.FormatConfigJsonConfigurationFileTests

open System
open Fantomas
open Fantomas.FormatConfig
open NUnit.Framework
open System.IO
open Fantomas.Tests.TestHelper

[<Literal>]
let private ConfigFileName ="fantomas-config.json"
let private ConfigFileName = "fantomas-config.json"

let private mkConfig subFolder config =
let json = Config.configToJson config
Expand Down
8 changes: 3 additions & 5 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1204,11 +1204,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 5155008

Please sign in to comment.