Skip to content

Commit

Permalink
Don't add additional new line before new. Fixes fsprojects#1049.
Browse files Browse the repository at this point in the history
  • Loading branch information
nojaf committed Aug 28, 2020
1 parent faf5419 commit 6b8f3ee
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/Fantomas.Tests/LetBindingTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -830,4 +830,32 @@ let notFound () =
new HttpResponseMessage(HttpStatusCode.NotFound,
Content = new StringContent(json, System.Text.Encoding.UTF8, "application/json"))
"""
"""

[<Test>]
let ``don't add additional newline before SynExpr.New, 1049`` () =
formatSourceString false """
let getVersion () =
let version =
let assembly =
typeof<FSharp.Compiler.SourceCodeServices.FSharpChecker>.Assembly
let version = assembly.GetName().Version
sprintf "%i.%i.%i" version.Major version.Minor version.Revision
new HttpResponseMessage(HttpStatusCode.OK,
Content = new StringContent(version, System.Text.Encoding.UTF8, "application/text"))
""" config
|> prepend newline
|> should equal """
let getVersion () =
let version =
let assembly =
typeof<FSharp.Compiler.SourceCodeServices.FSharpChecker>.Assembly
let version = assembly.GetName().Version
sprintf "%i.%i.%i" version.Major version.Minor version.Revision
new HttpResponseMessage(HttpStatusCode.OK,
Content = new StringContent(version, System.Text.Encoding.UTF8, "application/text"))
"""
1 change: 1 addition & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -1658,6 +1658,7 @@ and genExpr astContext synExpr =
| SynExpr.AnonRecd _ -> sepNlnConsideringTriviaContentBeforeFor SynExpr_AnonRecd e.Range
| SynExpr.ArrayOrListOfSeqExpr _ -> sepNlnConsideringTriviaContentBeforeFor SynExpr_ArrayOrListOfSeqExpr e.Range
| SynExpr.LongIdentSet _ -> sepNlnConsideringTriviaContentBeforeFor SynExpr_LongIdentSet e.Range
| SynExpr.New _ -> sepNlnConsideringTriviaContentBeforeFor SynExpr_New e.Range
| _ -> sepNln

atCurrentColumn (genLetOrUseList astContext bs +> ifElseCtx isInSameLine (!- " in ") sepNlnBeforeExpr +> genExpr astContext e)
Expand Down

0 comments on commit 6b8f3ee

Please sign in to comment.