From 042fbf61568efefbe4a934c22b8729a712509e3c Mon Sep 17 00:00:00 2001 From: Albert Meltzer <7529386+kitbellew@users.noreply.github.com> Date: Thu, 14 Nov 2024 11:03:19 -0800 Subject: [PATCH] FormatOps: implement binPack.parentCtor=ForceBreak --- .../src/main/scala/org/scalafmt/internal/FormatOps.scala | 2 ++ .../src/test/resources/binPack/ParentConstructors.stat | 8 ++++++-- .../shared/src/test/scala/org/scalafmt/FormatTests.scala | 2 +- 3 files changed, 9 insertions(+), 3 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 3d9d41a01..d6cc791af 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 @@ -960,6 +960,8 @@ class FormatOps( ) } else if (!isFirstCtor) Seq(Split(Space, 0), Split(Newline, 1)) + else if (style.binPack.parentConstructors eq BinPack.ParentCtors.ForceBreak) + Seq(Split(nlMod, 0, policy = nlPolicy(false)).withIndent(indent)) else { val parentCtors = style.binPack.parentConstructors val nlOnelineTag = parentCtors match { diff --git a/scalafmt-tests/shared/src/test/resources/binPack/ParentConstructors.stat b/scalafmt-tests/shared/src/test/resources/binPack/ParentConstructors.stat index 4757c688f..d15cae703 100644 --- a/scalafmt-tests/shared/src/test/resources/binPack/ParentConstructors.stat +++ b/scalafmt-tests/shared/src/test/resources/binPack/ParentConstructors.stat @@ -302,7 +302,9 @@ binPack.parentConstructors = ForceBreak === class SomeClass(a: Int, b: Double, c: String) extends SomeBaseClass with SomeTrait >>> -class SomeClass(a: Int, b: Double, c: String) extends SomeBaseClass with SomeTrait +class SomeClass(a: Int, b: Double, c: String) + extends SomeBaseClass + with SomeTrait <<< #4542 ForceBreak narrow multi-line maxColumn = 40 binPack.parentConstructors = ForceBreak @@ -336,4 +338,6 @@ class SomeClass(a: Int, b: Double, c: String) extends SomeBaseClass with SomeTrait >>> -class SomeClass(a: Int, b: Double, c: String) extends SomeBaseClass with SomeTrait +class SomeClass(a: Int, b: Double, c: String) + extends SomeBaseClass + with SomeTrait 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 02dd9a06b..325b2f890 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, 1117354, "total explored") + assertEquals(explored, 1117350, "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 :'(