Skip to content

Commit

Permalink
RemoveScala3OptionalBraces: allow leading infix op
Browse files Browse the repository at this point in the history
Previously, we didn't allow it as the scalameta library didn't provide
a way to check when it was actually possible.
  • Loading branch information
kitbellew committed Mar 17, 2024
1 parent 06d3195 commit 78bb7c8
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 19 deletions.
Expand Up @@ -76,7 +76,9 @@ private class RemoveScala3OptionalBraces(implicit val ftoks: FormatTokens)
case t: Term.Name =>
t.parent.exists {
case p: Term.Select => p.name eq t // select without `.`
case p: Term.ApplyInfix => p.op eq t
case p: Term.ApplyInfix if p.op eq t =>
!style.dialect.allowInfixOperatorAfterNL ||
!t.tokens.head.isSymbolicInfixOperator
case _ => false
}
case _ => false
Expand Down
8 changes: 4 additions & 4 deletions scalafmt-tests/src/test/resources/scala3/OptionalBraces.stat
Expand Up @@ -5211,10 +5211,10 @@ object a:
withEval.so(evalComment so { c =>
s"($c) "
}) +
this.match {
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
} + "."
this.match
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
+ "."
<<< match as infix lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
Expand Down
Expand Up @@ -4981,10 +4981,10 @@ object a {
}
>>>
object a:
withEval.so(evalComment so { c => s"($c) " }) + this.match {
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
} + "."
withEval.so(evalComment so { c => s"($c) " }) + this.match
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
+ "."
<<< match as infix lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
Expand Down
Expand Up @@ -5246,10 +5246,10 @@ object a:
withEval.so(evalComment so { c =>
s"($c) "
}) +
this.match {
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
} + "."
this.match
case MateAdvice(seq, _, _, _) => seq.desc
case CpAdvice(judgment, _, _) => judgment.toString
+ "."
<<< match as infix lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
Expand Down
Expand Up @@ -5373,12 +5373,12 @@ object a:
s"($c) "
}
) +
this.match {
case MateAdvice(seq, _, _, _) =>
seq.desc
case CpAdvice(judgment, _, _) =>
judgment.toString
} + "."
this.match
case MateAdvice(seq, _, _, _) =>
seq.desc
case CpAdvice(judgment, _, _) =>
judgment.toString
+ "."
<<< match as infix lhs, with rewrite
rewrite.scala3.removeOptionalBraces = yes
===
Expand Down

0 comments on commit 78bb7c8

Please sign in to comment.