Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FormatOps: fix cond between while and do #4139

Merged
merged 2 commits into from
Aug 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2013,7 +2013,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
13 changes: 13 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Original file line number Diff line number Diff line change
Expand Up @@ -633,6 +633,19 @@ object a:
while (foo) do
foo
bar
<<< redundant braces and parens around while-do cond
rewrite.rules = [RedundantParens, RedundantBraces]
===
object a:
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
12 changes: 12 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_fold.stat
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,18 @@ object a:
while (foo) do
foo
bar
<<< redundant braces and parens around while-do cond
rewrite.rules = [RedundantParens, RedundantBraces]
===
object a:
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
15 changes: 15 additions & 0 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces_keep.stat
Original file line number Diff line number Diff line change
Expand Up @@ -653,6 +653,21 @@ object a:
while (foo) do
foo
bar
<<< redundant braces and parens around while-do cond
rewrite.rules = [RedundantParens, RedundantBraces]
===
object a:
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 @@ -683,6 +683,19 @@ object a:
while (foo) do
foo
bar
<<< redundant braces and parens around while-do cond
rewrite.rules = [RedundantParens, RedundantBraces]
===
object a:
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
Loading