Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add brace before indentation #836

Merged
merged 5 commits into from
May 16, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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