Skip to content

Commit a7a85c3

Browse files
authored
Merge pull request #549 from bjaglin/update/sbt-scalafix-0.10.0
scalafix 0.10.1
2 parents a3411ab + 3174d0d commit a7a85c3

File tree

3 files changed

+20
-19
lines changed

3 files changed

+20
-19
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

project/plugins.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@ addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "1.2.0
33
addSbtPlugin("org.scala-native" % "sbt-scala-native" % "0.4.5")
44
addSbtPlugin("org.portable-scala" % "sbt-scala-native-crossproject" % "1.2.0")
55
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "3.0.1")
6-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.34")
6+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.10.1")
77
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.11.0")

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

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -53,28 +53,29 @@ 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
62+
.copy(
63+
args = Term.Apply(col, ap.args) :: Nil,
64+
op = Term.Name(doubleOp * 2)
65+
)
66+
.toString()
67+
ctx.replaceTree(ap, newAp)
6768
}
6869

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

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

76-
case Term.ApplyInfix(_, op @ mapPlus(_), Nil, List(rhs)) =>
77-
rewriteOp(op, rhs, "+", "Map")
77+
case ap @ Term.ApplyInfix(_, op @ mapPlus(_), Nil, _) =>
78+
rewriteOp(ap, "+", "Map")
7879
}.asPatch
7980
}
8081

0 commit comments

Comments
 (0)