Skip to content

Commit f1d0289

Browse files
committed
Splits: handle do-while conditions as well
1 parent f4faa6b commit f1d0289

File tree

10 files changed

+40
-28
lines changed

10 files changed

+40
-28
lines changed

scalafmt-core/shared/src/main/scala/org/scalafmt/internal/Splits.scala

+2-4
Original file line numberDiff line numberDiff line change
@@ -2003,12 +2003,10 @@ object SplitsAfterLeftParen extends Splits {
20032003
else alignIndents,
20042004
))
20052005
}
2006-
def withCond(t: Tree.WithCond) =
2007-
if (isTokenHeadOrBefore(left, t)) None else impl(isEnclosedInBraces(t.cond))
20082006
leftOwner match { // If/For/While/For with (
20092007
case t: Term.EnumeratorsBlock if getHeadOpt(t).contains(ft) => impl(false)
2010-
case t: Term.If => withCond(t)
2011-
case t: Term.While => withCond(t)
2008+
case t: Tree.WithCond if !isTokenHeadOrBefore(left, t) =>
2009+
impl(isEnclosedInBraces(t.cond))
20122010
case _ => None
20132011
}
20142012
}

scalafmt-tests-community/intellij/shared/src/test/scala/org/scalafmt/community/intellij/CommunityIntellijScalaSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ abstract class CommunityIntellijScalaSuite(name: String)
1313
class CommunityIntellijScala_2024_2_Suite
1414
extends CommunityIntellijScalaSuite("intellij-scala-2024.2") {
1515

16-
override protected def totalStatesVisited: Option[Int] = Some(59399907)
16+
override protected def totalStatesVisited: Option[Int] = Some(59404572)
1717

1818
override protected def builds = Seq {
1919
getBuild(
@@ -54,7 +54,7 @@ class CommunityIntellijScala_2024_2_Suite
5454
class CommunityIntellijScala_2024_3_Suite
5555
extends CommunityIntellijScalaSuite("intellij-scala-2024.3") {
5656

57-
override protected def totalStatesVisited: Option[Int] = Some(59614646)
57+
override protected def totalStatesVisited: Option[Int] = Some(59619311)
5858

5959
override protected def builds = Seq {
6060
getBuild(

scalafmt-tests-community/scala2/shared/src/test/scala/org/scalafmt/community/scala2/CommunityScala2Suite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ abstract class CommunityScala2Suite(name: String)
99

1010
class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {
1111

12-
override protected def totalStatesVisited: Option[Int] = Some(42553260)
12+
override protected def totalStatesVisited: Option[Int] = Some(42553676)
1313

1414
override protected def builds =
1515
Seq(getBuild("v2.12.20", dialects.Scala212, 1277))
@@ -18,7 +18,7 @@ class CommunityScala2_12Suite extends CommunityScala2Suite("scala-2.12") {
1818

1919
class CommunityScala2_13Suite extends CommunityScala2Suite("scala-2.13") {
2020

21-
override protected def totalStatesVisited: Option[Int] = Some(53018051)
21+
override protected def totalStatesVisited: Option[Int] = Some(53018427)
2222

2323
override protected def builds =
2424
Seq(getBuild("v2.13.14", dialects.Scala213, 1287))

scalafmt-tests-community/spark/shared/src/test/scala/org/scalafmt/community/spark/CommunitySparkSuite.scala

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ abstract class CommunitySparkSuite(name: String)
99

1010
class CommunitySpark3_4Suite extends CommunitySparkSuite("spark-3.4") {
1111

12-
override protected def totalStatesVisited: Option[Int] = Some(85964934)
12+
override protected def totalStatesVisited: Option[Int] = Some(85967060)
1313

1414
override protected def builds = Seq(getBuild("v3.4.1", dialects.Scala213, 2585))
1515

1616
}
1717

1818
class CommunitySpark3_5Suite extends CommunitySparkSuite("spark-3.5") {
1919

20-
override protected def totalStatesVisited: Option[Int] = Some(90969442)
20+
override protected def totalStatesVisited: Option[Int] = Some(90971586)
2121

2222
override protected def builds = Seq(getBuild("v3.5.3", dialects.Scala213, 2756))
2323

scalafmt-tests/shared/src/test/resources/newlines/source_classic.stat

+3-1
Original file line numberDiff line numberDiff line change
@@ -12093,7 +12093,9 @@ def foo = {
1209312093
def foo = {
1209412094
next.offset = begCharOffset
1209512095
do putCharAndNext()
12096-
while (ch != CR && ch != LF && ch != FF && ch != SU)
12096+
while (
12097+
ch != CR && ch != LF && ch != FF && ch != SU
12098+
)
1209712099
}
1209812100
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
1209912101
maxColumn = 60

scalafmt-tests/shared/src/test/resources/newlines/source_fold.stat

+10-6
Original file line numberDiff line numberDiff line change
@@ -11319,8 +11319,10 @@ def foo = {
1131911319
>>>
1132011320
def foo = {
1132111321
next.offset = begCharOffset
11322-
do putCharAndNext() while (ch != CR &&
11323-
ch != LF && ch != FF && ch != SU)
11322+
do putCharAndNext() while (
11323+
ch != CR && ch != LF && ch != FF &&
11324+
ch != SU
11325+
)
1132411326
}
1132511327
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
1132611328
maxColumn = 60
@@ -11334,8 +11336,9 @@ def foo = {
1133411336
>>>
1133511337
def foo = {
1133611338
next.offset = begCharOffset
11337-
do putCharAndNext()
11338-
while (ch != CR && ch != LF && ch != FF && ch != SU)
11339+
do putCharAndNext() while (
11340+
ch != CR && ch != LF && ch != FF && ch != SU
11341+
)
1133911342
}
1134011343
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
1134111344
danglingParentheses.ctrlSite = false
@@ -11348,8 +11351,9 @@ def foo = {
1134811351
>>>
1134911352
def foo = {
1135011353
next.offset = begCharOffset
11351-
do putCharAndNext() while (ch != CR &&
11352-
ch != LF && ch != FF && ch != SU)
11354+
do putCharAndNext()
11355+
while (ch != CR && ch != LF &&
11356+
ch != FF && ch != SU)
1135311357
}
1135411358
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
1135511359
maxColumn = 60

scalafmt-tests/shared/src/test/resources/newlines/source_keep.stat

+3-1
Original file line numberDiff line numberDiff line change
@@ -11865,7 +11865,9 @@ def foo = {
1186511865
def foo = {
1186611866
next.offset = begCharOffset
1186711867
do putCharAndNext()
11868-
while (ch != CR && ch != LF && ch != FF && ch != SU)
11868+
while (
11869+
ch != CR && ch != LF && ch != FF && ch != SU
11870+
)
1186911871
}
1187011872
<<< `do` starts a new statement, wide, danglingParentheses.ctrlSite
1187111873
maxColumn = 60

scalafmt-tests/shared/src/test/resources/newlines/source_unfold.stat

+6-6
Original file line numberDiff line numberDiff line change
@@ -12350,8 +12350,9 @@ def foo = {
1235012350
>>>
1235112351
def foo = {
1235212352
next.offset = begCharOffset
12353-
do putCharAndNext()
12354-
while (ch != CR && ch != LF && ch != FF && ch != SU)
12353+
do putCharAndNext() while (
12354+
ch != CR && ch != LF && ch != FF && ch != SU
12355+
)
1235512356
}
1235612357
<<< `do` starts a new statement, narrow, !danglingParentheses.ctrlSite
1235712358
danglingParentheses.ctrlSite = false
@@ -12364,10 +12365,9 @@ def foo = {
1236412365
>>>
1236512366
def foo = {
1236612367
next.offset = begCharOffset
12367-
do putCharAndNext() while (
12368-
ch != CR && ch != LF && ch != FF &&
12369-
ch != SU
12370-
)
12368+
do putCharAndNext()
12369+
while (ch != CR && ch != LF &&
12370+
ch != FF && ch != SU)
1237112371
}
1237212372
<<< `do` starts a new statement, wide, !danglingParentheses.ctrlSite
1237312373
maxColumn = 60

scalafmt-tests/shared/src/test/resources/rewrite/RedundantBraces.stat

+9-3
Original file line numberDiff line numberDiff line change
@@ -2480,9 +2480,15 @@ object a {
24802480
>>>
24812481
object a {
24822482
do foo
2483-
while (true)
2483+
while (
2484+
true
2485+
)
24842486
do a + b
2485-
while (true)
2487+
while (
2488+
true
2489+
)
24862490
do a + b
2487-
while (true)
2491+
while (
2492+
true
2493+
)
24882494
}

scalafmt-tests/shared/src/test/scala/org/scalafmt/FormatTests.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ class FormatTests extends FunSuite with CanRunTests with FormatAssertions {
148148
val explored = Debug.explored.get()
149149
logger.debug(s"Total explored: $explored")
150150
if (!onlyUnit && !onlyManual)
151-
assertEquals(explored, 2551504, "total explored")
151+
assertEquals(explored, 2552242, "total explored")
152152
// TODO(olafur) don't block printing out test results.
153153
TestPlatformCompat.executeAndWait(PlatformFileOps.writeFile(
154154
FileOps.getPath("target", "index.html"),

0 commit comments

Comments
 (0)