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

RedundantParens: don't allow breaks in infix sides #3224

Merged
merged 2 commits into from
May 19, 2022
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 @@ -107,6 +107,7 @@ class RedundantParens(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
case InfixApp(pia) if !infixNeedsParens(pia, t) =>
t match {
case InfixApp(tia) =>
!breaksBeforeOp(tia) &&
style.rewrite.redundantParens.infixSide.exists {
case RedundantParensSettings.InfixSide.many =>
tia.op.value == pia.op.value ||
Expand Down
16 changes: 16 additions & 0 deletions scalafmt-tests/src/test/resources/rewrite/RedundantParens.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1025,6 +1025,22 @@ object a {
// all
foo || bar && baz // low precedence infix
}
<<< infix expressions with infixSide = all and breaks
rewrite.redundantParens.infixSide = all
===
object a {
foo and (
bar
+ baz
)
}
>>>
object a {
foo and (
bar
+ baz
)
}
<<< #3222 do-while
object a {
do foo while (true)
Expand Down