Skip to content

Commit

Permalink
RedundantParens: exclude case of trailing commas
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jan 7, 2024
1 parent 768a47c commit f5c51e1
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ class RedundantParens(ftoks: FormatTokens) extends FormatTokensRewrite.Rule {
style: ScalafmtConfig
): Option[(Replacement, Replacement)] =
ft.right match {
case _: Token.RightParen if left.how eq ReplacementType.Remove =>
case _: Token.RightParen
if (left.how eq ReplacementType.Remove) && // check trailing comma
!ftoks.prevNonComment(ft).left.is[Token.Comma] =>
Some((left, removeToken))
case _ => None
}
Expand Down
27 changes: 18 additions & 9 deletions scalafmt-tests/src/test/resources/rewrite/RedundantParens.stat
Original file line number Diff line number Diff line change
Expand Up @@ -1334,12 +1334,15 @@ object A {
Option(""),
).map(identity)}
>>>
test does not parse
object A {
def test =
foo,
(
foo,
)
def test =
Option(""), .map(identity)
(
Option(""),
).map(identity)
}
<<< #3743 trailingCommas = never
rewrite.trailingCommas.style = never
Expand All @@ -1354,12 +1357,15 @@ object A {
Option(""),
).map(identity)}
>>>
test does not parse
object A {
def test =
foo,
(
foo,
)
def test =
Option(""), .map(identity)
(
Option(""),
).map(identity)
}
<<< #3743 trailingCommas = keep
rewrite.trailingCommas.style = keep
Expand All @@ -1374,10 +1380,13 @@ object A {
Option(""),
).map(identity)}
>>>
test does not parse
object A {
def test =
foo,
(
foo,
)
def test =
Option(""), .map(identity)
(
Option(""),
).map(identity)
}

0 comments on commit f5c51e1

Please sign in to comment.