Skip to content

Commit

Permalink
FormatOps: fix cond between while and do
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Aug 6, 2024
1 parent ff84fb2 commit bc090bb
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2016,7 +2016,8 @@ class FormatOps(
style: ScalafmtConfig,
): Option[OptionalBracesRegion] = ft.meta.leftOwner match {
case t @ Term.While(b: Term.Block, _)
if !matchingOpt(nft.right).exists(_.end >= b.pos.end) =>
if isMultiStatBlock(b) &&
!matchingOpt(nft.right).exists(_.end >= b.pos.end) =>
Some(new OptionalBracesRegion {
def owner = Some(t)
def splits = Some {
Expand Down
10 changes: 3 additions & 7 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -699,13 +699,9 @@ object a:
i -= 1
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
object a:
- while i > 0 && foo
+ while
+ i > 0 && foo
do i -= 1
object a:
while i > 0 && foo
do i -= 1
<<< nested if-else multiple
object a:
val a =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -677,13 +677,8 @@ object a:
i -= 1
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
object a:
- while i > 0 && foo do i -= 1
+ while
+ i > 0 && foo
+ do i -= 1
object a:
while i > 0 && foo do i -= 1
<<< nested if-else multiple
object a:
val a =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -752,14 +752,9 @@ object a:
i -= 1
}
>>>
Idempotency violated
=> Diff (- obtained, + expected)
object a:
- while i > 0 && foo do
+ while
+ i > 0 && foo
+ do
i -= 1
object a:
while i > 0 && foo do
i -= 1
<<< nested if-else multiple
object a:
val a =
Expand Down

0 comments on commit bc090bb

Please sign in to comment.