From 2f3830a37dceeccebf66422c565b6a264e0c44f9 Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 31 Oct 2024 18:29:54 -0700 Subject: [PATCH] Router: use single non-NL default split before `}` The usual NL split is forced through NB policy used with `{`. --- .../shared/src/main/scala/org/scalafmt/internal/Router.scala | 5 +++-- .../shared/src/test/resources/default/Idempotency.stat | 5 ++--- scalafmt-tests/shared/src/test/resources/unit/Apply.stat | 5 ++--- .../shared/src/test/scala/org/scalafmt/FormatTests.scala | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala index 79d0b02a74..60a71bcd84 100644 --- a/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala +++ b/scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Router.scala @@ -651,8 +651,9 @@ class Router(formatOps: FormatOps) { ) } - case FormatToken(_, T.RightBrace(), _) => - Seq(Split(xmlSpace(rightOwner), 0), Split(Newline2x(ft), 0)) + case FormatToken(_, _: T.RightBrace, _) => + Seq(Split(if (ft.hasBlankLine) Newline2x else xmlSpace(rightOwner), 0)) + case FormatToken(_: T.KwPackage, _, _) if leftOwner.is[Pkg] => Seq(Split(Space, 0)) // Opening [ with no leading space. diff --git a/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat b/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat index e2f49186d7..fcad6d784f 100644 --- a/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat +++ b/scalafmt-tests/shared/src/test/resources/default/Idempotency.stat @@ -26,9 +26,8 @@ val bindingFuture = Http().bindAndHandleSync({ { val bindingFuture = Http().bindAndHandleSync( { case HttpRequest(_, _, headers, _, _) ⇒ - val upgrade = headers.collectFirst { case u: UpgradeToWebSocket ⇒ - u - }.get + val upgrade = + headers.collectFirst { case u: UpgradeToWebSocket ⇒ u }.get upgrade.handleMessages( Flow.fromSinkAndSource(Sink.ignore, Source.fromPublisher(source)), diff --git a/scalafmt-tests/shared/src/test/resources/unit/Apply.stat b/scalafmt-tests/shared/src/test/resources/unit/Apply.stat index 23e02fdb58..73406c822f 100644 --- a/scalafmt-tests/shared/src/test/resources/unit/Apply.stat +++ b/scalafmt-tests/shared/src/test/resources/unit/Apply.stat @@ -24,9 +24,8 @@ new DenseMatrix( isTranspose = !from.isTranspose) >>> new DenseMatrix( - data = from.data map { - _.conjugate - }, + data = + from.data map { _.conjugate }, offset = from.offset, cols = from.rows, rows = from.cols, diff --git a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala index 5bd95d36ba..feaac55e9e 100644 --- a/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala +++ b/scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala @@ -137,7 +137,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions { val explored = Debug.explored.get() logger.debug(s"Total explored: $explored") if (!onlyUnit && !onlyManual) - assertEquals(explored, 1487221, "total explored") + assertEquals(explored, 1486615, "total explored") val results = debugResults.result() // TODO(olafur) don't block printing out test results. // I don't want to deal with scalaz's Tasks :'(