From 4491b9339812c26bece154319ac881f1d52a5a5c Mon Sep 17 00:00:00 2001 From: Josh DeGraw <18509575+josh-degraw@users.noreply.github.com> Date: Fri, 5 May 2023 02:31:53 -0600 Subject: [PATCH] Fix stroustrup formatting issue with trivia (#2873) * Fix stroustrup formatting issue with trivia * Update changelog --------- Co-authored-by: Florian Verdonck --- CHANGELOG.md | 3 ++- .../SynTypeDefnSimpleReprRecordTests.fs | 27 +++++++++++++++++-- src/Fantomas.Core/CodePrinter.fs | 2 +- 3 files changed, 28 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 62f9def8db..f4223ed0cc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,10 @@ # Changelog -## [Unreleased] +## [6.0.2] - 2023-05-05 ### Fixed * Incorrect indentation of compiler-conditional accessibility modifier for module definition. [#2867](https://github.com/fsprojects/fantomas/issues/2867) +* Comment above the record bracket beaks formatting when MultilineBracketStyle is Stroustrup. [#2871](https://github.com/fsprojects/fantomas/issues/2871) ## [6.0.1] - 2023-04-19 diff --git a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs index 03653f643b..2cfe501e3e 100644 --- a/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs +++ b/src/Fantomas.Core.Tests/Stroustrup/SynTypeDefnSimpleReprRecordTests.fs @@ -296,7 +296,7 @@ type MangaDexAtHomeResponse = { """ [] -let ``record interface declarations can break with Stroustrup enabled, 2787 `` () = +let ``record interface declarations can break with Stroustrup enabled, 2787`` () = formatSourceString false """ @@ -329,7 +329,7 @@ type UpdatedName = { PreviousName: string } """ [] -let ``record member declarations can break with Stroustrup enabled, 2787 `` () = +let ``record member declarations can break with Stroustrup enabled, 2787`` () = formatSourceString false """ @@ -354,3 +354,26 @@ type SomeEvent = { type UpdatedName = { PreviousName: string } """ + +[] +let ``comment above record bracket breaks formatting when Stroustrup enabled, 2871`` () = + formatSourceString + false + """ +type Event = + // TODO: Add LulaSafe conclusion and scores per assessment + { + Metadata: AssessmentMetadata + } +""" + config + |> prepend newline + |> should + equal + """ +type Event = + // TODO: Add LulaSafe conclusion and scores per assessment + { + Metadata: AssessmentMetadata + } +""" diff --git a/src/Fantomas.Core/CodePrinter.fs b/src/Fantomas.Core/CodePrinter.fs index ef787fa2a0..c1ea86dbff 100644 --- a/src/Fantomas.Core/CodePrinter.fs +++ b/src/Fantomas.Core/CodePrinter.fs @@ -3375,7 +3375,7 @@ let genTypeDefn (td: TypeDefn) = let size = getRecordSize ctx node.Fields let short = bodyExpr size - if ctx.Config.IsStroustrupStyle then + if ctx.Config.IsStroustrupStyle && not node.OpeningBrace.HasContentBefore then (sepSpace +> short) ctx else isSmallExpression size short (indentSepNlnUnindent short) ctx