diff --git a/src/Fantomas.Tests/ModuleTests.fs b/src/Fantomas.Tests/ModuleTests.fs index e56478b888..dee5749f7e 100644 --- a/src/Fantomas.Tests/ModuleTests.fs +++ b/src/Fantomas.Tests/ModuleTests.fs @@ -512,3 +512,35 @@ namespace foo.quz // bar // baz """ + +[] +let ``don't add extra new lines between comments and attributes, 1108`` () = + formatSourceString false """ +namespace Foo + +// First +[] + +// Second +[] + +// Third +[] + +do () +""" config + |> prepend newline + |> should equal """ +namespace Foo + +// First +[] + +// Second +[] + +// Third +[] + +do () +""" diff --git a/src/Fantomas/CodePrinter.fs b/src/Fantomas/CodePrinter.fs index c7c7716ced..6796e74a9a 100644 --- a/src/Fantomas/CodePrinter.fs +++ b/src/Fantomas/CodePrinter.fs @@ -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)