Skip to content

Commit 5a614d8

Browse files
committed
handle scalameta change in ApplyInfix RHS positions
scalameta/scalameta#2684, first released in scalameta 4.5.1 (scalafix 0.10.0), changed a behavior, so this takes a more intrusive but also more robust approach so that the rule works with scalafix 0.10.x.
1 parent 5a29c34 commit 5a614d8

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ The migration rules use scalafix. Please see the [official installation instruct
5353

5454
```scala
5555
// project/plugins.sbt
56-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
56+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
5757
```
5858

5959
### Collection213Upgrade

scalafix/rules/src/main/scala/scala/fix/collection/Collection213Experimental.scala

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,27 @@ case class Collection213ExperimentalV0(index: SemanticdbIndex)
5353
}
5454

5555
def replaceSetMapPlusMinus(ctx: RuleCtx): Patch = {
56-
def rewriteOp(op: Tree, rhs: Tree, doubleOp: String, col0: String): Patch = {
57-
val col = "_root_.scala.collection." + col0
58-
val callSite =
59-
if (startsWithParens(rhs)) {
60-
ctx.addLeft(rhs, col)
61-
} else {
62-
ctx.addLeft(rhs, col + "(") +
63-
ctx.addRight(rhs, ")")
64-
}
65-
66-
ctx.addRight(op, doubleOp) + callSite
56+
def rewriteOp(ap: Term.ApplyInfix, doubleOp: String, col0: String): Patch = {
57+
val col = col0 match {
58+
case "Set" => q"_root_.scala.collection.Set"
59+
case "Map" => q"_root_.scala.collection.Map"
60+
}
61+
val newAp = ap.copy(
62+
args = Term.Apply(col, ap.args) :: Nil,
63+
op = Term.Name(doubleOp*2)
64+
).toString()
65+
ctx.replaceTree(ap, newAp)
6766
}
6867

6968
ctx.tree.collect {
70-
case ap @ Term.ApplyInfix(CollectionSet(), op @ setPlus(_), Nil, List(rhs)) =>
71-
rewriteOp(op, rhs, "+", "Set")
69+
case ap @ Term.ApplyInfix(CollectionSet(), setPlus(_), Nil, _) =>
70+
rewriteOp(ap, "+", "Set")
7271

73-
case Term.ApplyInfix(CollectionSet(), op @ setMinus(_), Nil, List(rhs)) =>
74-
rewriteOp(op, rhs, "-", "Set")
72+
case ap @ Term.ApplyInfix(CollectionSet(), setMinus(_), Nil, _) =>
73+
rewriteOp(ap, "-", "Set")
7574

76-
case Term.ApplyInfix(_, op @ mapPlus(_), Nil, List(rhs)) =>
77-
rewriteOp(op, rhs, "+", "Map")
75+
case ap @ Term.ApplyInfix(_, op @ mapPlus(_), Nil, _) =>
76+
rewriteOp(ap, "+", "Map")
7877
}.asPatch
7978
}
8079

0 commit comments

Comments
 (0)