Skip to content

Commit

Permalink
Don't add new line before SynAttributeList when previous SynAttribute…
Browse files Browse the repository at this point in the history
…List had content after. Fixes fsprojects#1108.
  • Loading branch information
nojaf committed Sep 5, 2020
1 parent de00dc4 commit f8c092e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
32 changes: 32 additions & 0 deletions src/Fantomas.Tests/ModuleTests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -512,3 +512,35 @@ namespace foo.quz
// bar
// baz
"""

[<Test>]
let ``don't add extra new lines between comments and attributes, 1108`` () =
formatSourceString false """
namespace Foo
// First
[<someAnnotation>]
// Second
[<someAnnotation>]
// Third
[<someAnnotation>]
do ()
""" config
|> prepend newline
|> should equal """
namespace Foo
// First
[<someAnnotation>]
// Second
[<someAnnotation>]
// Third
[<someAnnotation>]
do ()
"""
2 changes: 2 additions & 0 deletions src/Fantomas/CodePrinter.fs
Original file line number Diff line number Diff line change
Expand Up @@ -351,6 +351,8 @@ and genModuleDecl astContext (node: SynModuleDecl) =
let hasContentAfter =
TriviaHelpers.``has content after after that matches`` (fun tn ->
RangeHelpers.rangeEq tn.Range a.Range) (function
| Newline
| Comment (LineCommentOnSingleLine (_))
| Directive (_) -> true
| _ -> false) (Map.tryFindOrEmptyList SynAttributeList_ ctx.TriviaMainNodes)

Expand Down

0 comments on commit f8c092e

Please sign in to comment.