From 97c4a2e2b4fc7a85fc0a2607b7a28bd273945349 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Tue, 1 Oct 2024 23:23:42 -0700 Subject: [PATCH] FormatOps: use optimal slb end in binpacked `(...` --- .../src/main/scala/org/scalafmt/internal/FormatOps.scala | 3 ++- .../shared/src/test/resources/scala3/OptionalBraces.stat | 3 +-- .../shared/src/test/resources/scala3/OptionalBraces_fold.stat | 3 +-- .../shared/src/test/resources/scala3/OptionalBraces_keep.stat | 3 +-- .../src/test/resources/scala3/OptionalBraces_unfold.stat | 3 +-- scalafmt-tests/shared/src/test/resources/unit/Comment.stat | 3 ++- 6 files changed, 8 insertions(+), 10 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala index 9e8f251cd8..e04a273044 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/FormatOps.scala @@ -1057,9 +1057,10 @@ class FormatOps( } val noSyntaxNL = extendsThenWith val pnlPolicy = PenalizeAllNewlines(lastToken, 1, noSyntaxNL = noSyntaxNL) + val slbEnd = endOfSingleLineBlock(lastFt) Seq( Split(Space, 0) - .withSingleLine(lastToken, exclude = exclude, noSyntaxNL = noSyntaxNL) + .withSingleLine(slbEnd, exclude = exclude, noSyntaxNL = noSyntaxNL) .orPolicy(pnlPolicy).withIndent(indent), Split(nlMod, 0).onlyIf(nlOnelineTag != Right(false)) .preActivateFor(nlOnelineTag.left.toOption) diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat index 2c245af774..5f9547d74d 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces.stat @@ -7340,6 +7340,5 @@ object Parsers: >>> object Parsers: enum Location(inArgs: Boolean): - case InPatternArgs - extends Location(false, true, + case InPatternArgs extends Location(false, true, true) // InParens not true, since it might be an alternative diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat index e2146c74a1..92bd396e07 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_fold.stat @@ -7060,7 +7060,6 @@ object Parsers: >>> object Parsers: enum Location(inArgs: Boolean): - case InPatternArgs - extends Location( + case InPatternArgs extends Location( false, true, true ) // InParens not true, since it might be an alternative diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat index 96ab030ab0..51e2359c98 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_keep.stat @@ -7371,6 +7371,5 @@ object Parsers: >>> object Parsers: enum Location(inArgs: Boolean): - case InPatternArgs - extends Location(false, true, + case InPatternArgs extends Location(false, true, true) // InParens not true, since it might be an alternative diff --git a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat index f753e7ad60..67861cc01d 100644 --- a/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat +++ b/scalafmt-tests/shared/src/test/resources/scala3/OptionalBraces_unfold.stat @@ -7631,7 +7631,6 @@ object Parsers: >>> object Parsers: enum Location(inArgs: Boolean): - case InPatternArgs - extends Location( + case InPatternArgs extends Location( false, true, true ) // InParens not true, since it might be an alternative diff --git a/scalafmt-tests/shared/src/test/resources/unit/Comment.stat b/scalafmt-tests/shared/src/test/resources/unit/Comment.stat index 4efbb0f079..42c0d4c001 100644 --- a/scalafmt-tests/shared/src/test/resources/unit/Comment.stat +++ b/scalafmt-tests/shared/src/test/resources/unit/Comment.stat @@ -219,7 +219,8 @@ object literal extends scala.Dynamic { // scalastyle:ignore ??? } >>> -object literal extends scala.Dynamic { // scalastyle:ignore +object literal + extends scala.Dynamic { // scalastyle:ignore ??? } <<< #1234 1: single-line