Skip to content

Commit

Permalink
RedundantParens: allow any Ref, not just Name
Browse files Browse the repository at this point in the history
  • Loading branch information
kitbellew committed Jun 23, 2024
1 parent 27255bb commit 1bcb961
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,13 +141,13 @@ class RedundantParens(implicit val ftoks: FormatTokens)
private def okToReplaceOther(
t: Tree,
)(implicit style: ScalafmtConfig): Boolean = t match {
case _: Lit | _: Name | _: Term.Interpolate => true
case _: Term.PartialFunction | _: Member.Apply => true
case _: Lit | _: Member.Apply | _: Term.Interpolate |
_: Term.PartialFunction => true
case t: Term.Select => ftoks.tokenBefore(t.name).left.is[Token.Dot]
case t: Term.Match
if style.dialect.allowMatchAsOperator &&
ftoks.tokenAfter(t.expr).right.is[Token.Dot] &&
ftoks.tokenBefore(t.cases).left.is[Token.LeftBrace] => true
case _: Ref => true // Ref must be after Select
case t: Term.Match => style.dialect.allowMatchAsOperator &&
ftoks.tokenAfter(t.expr).right.is[Token.Dot] && // like select
ftoks.tokenBefore(t.cases).left.is[Token.LeftBrace]
case _ => false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1423,7 +1423,7 @@ object a {
>>>
object a {
val (a: Int) = b
var (c: (foo.Int)) = d
var (c: foo.Int) = d
val (a: (A | B)) = b
var (c: (C & D)) = d
val (a: (A | B), c: (C & D)) = (b, d)
Expand All @@ -1444,10 +1444,10 @@ object a {
>>>
object a {
def g(h: Int): String
def g(h: Int): (foo.String)
def g(h: Int): foo.String
def g(h: Int): foo.String[A]
def g(h: Int): String = ???
def g(h: Int): (foo.String) = ???
def g(h: Int): foo.String = ???
def g(h: Int): foo.String[A] = ???
def g(h: (Int | Long)): (foo & bar) = ???
def g(h: (A & B)): (foo | bar[A]) = ???
Expand Down

0 comments on commit 1bcb961

Please sign in to comment.