Skip to content

Commit 362d648

Browse files
Upgrade Scalafix to 0.5.3
1 parent 8c9097f commit 362d648

File tree

7 files changed

+35
-52
lines changed

7 files changed

+35
-52
lines changed

build.sbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,9 @@ inScope(Global)(
77

88
lazy val root = project
99
.in(file("."))
10-
.aggregate(rewrites, input, output, tests)
10+
.aggregate(rules, input, output, tests)
1111

12-
lazy val rewrites = project.settings(
12+
lazy val rules = project.settings(
1313
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
1414
)
1515

@@ -41,5 +41,5 @@ lazy val tests = project
4141
classDirectory.in(input, Compile).value
4242
)
4343
)
44-
.dependsOn(input, rewrites)
44+
.dependsOn(input, rules)
4545
.enablePlugins(BuildInfoPlugin)

input/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
rewrite = "scala:fix.Collectionstrawman_v0"
2+
rule = "scala:fix.Collectionstrawman_v0"
33
*/
44
package fix
55

input/src/main/scala/fix/Collectionstrawman_v0_Traversable.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
rewrite = "scala:fix.Collectionstrawman_v0"
2+
rule = "scala:fix.Collectionstrawman_v0"
33
*/
44
package fix
55

input/src/main/scala/fix/ListTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
rewrite = "scala:fix.Collectionstrawman_v0"
2+
rule = "scala:fix.Collectionstrawman_v0"
33
*/
44
package fix
55

project/plugins.sbt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.0-M4")
2-
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC9")
3-
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")
4-
1+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.3")
2+
addSbtPlugin("io.get-coursier" % "sbt-coursier" % "1.0.0-RC10")
3+
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.6.1")

rewrites/src/main/scala/fix/Collectionstrawman_v0.scala renamed to rules/src/main/scala/fix/Collectionstrawman_v0.scala

Lines changed: 24 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@ package fix
22

33
import scalafix._
44
import scalafix.syntax._
5+
import scalafix.util._
56
import scala.meta._
67

7-
case class Collectionstrawman_v0(sctx: SemanticCtx)
8-
extends SemanticRewrite(sctx) {
8+
case class Collectionstrawman_v0(index: SemanticdbIndex)
9+
extends SemanticRule(index, "Collectionstrawman_v0") {
910

1011
implicit class XtensionSymbolCollection(symbol: Symbol) {
1112
def name = symbol match {
@@ -27,10 +28,10 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
2728
"intArrayOps" -> "genericArrayOps"
2829
)
2930

30-
def replaceExtensionMethods(ctx: RewriteCtx): Patch = {
31+
def replaceExtensionMethods(ctx: RuleCtx): Patch = {
3132
val toImport = for {
32-
r <- ctx.semanticCtx.names
33-
in = r.sym.normalized
33+
r <- ctx.index.names
34+
in = r.symbol.normalized
3435
out <- unimports.get(in).toList
3536
} yield {
3637
val name = in.name
@@ -51,20 +52,20 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
5152
"_root_.scala.runtime.RichInt#to(I)Lscala/collection/immutable/Range/Inclusive;.")
5253
val rangeSymbol = Symbol(
5354
"_root_.scala.runtime.RichInt#until(I)Lscala/collection/immutable/Range;.")
54-
def replaceRange(ctx: RewriteCtx): Patch = {
55+
def replaceRange(ctx: RuleCtx): Patch = {
5556
ctx.tree.collect {
56-
case tree @ Term.ApplyInfix(lhs, op, targs, arg :: Nil)
57+
case tree @ Term.ApplyInfix(lhs, op, _, arg :: Nil)
5758
if op.symbol.contains(inclusiveRange) =>
5859
ctx.replaceTree(tree, q"Range.inclusive($lhs, $arg)".syntax) +
5960
ctx.addGlobalImport(rangeImport)
60-
case tree @ Term.ApplyInfix(lhs, op, targs, arg :: Nil)
61+
case tree @ Term.ApplyInfix(lhs, op, _, arg :: Nil)
6162
if op.symbol.contains(rangeSymbol) =>
6263
ctx.replaceTree(tree, q"Range($lhs, $arg)".syntax) +
6364
ctx.addGlobalImport(rangeImport)
6465
}
6566
}.asPatch
6667

67-
def replaceSymbols(ctx: RewriteCtx): Patch = {
68+
def replaceSymbols(ctx: RuleCtx): Patch = {
6869
def p(name: String) =
6970
s"scala.Predef.$name" -> s"strawman.collection.immutable.$name"
7071
def s(name: String, rename: Option[String] = None) =
@@ -101,57 +102,40 @@ case class Collectionstrawman_v0(sctx: SemanticCtx)
101102
)
102103
}
103104

104-
case class SymbolMatcher(symbols: Symbol*) {
105-
def unapply(arg: Tree): Option[(Tree, Symbol)] =
106-
sctx.symbol(arg.pos).flatMap { sym =>
107-
if (symbols.exists(_.isSameNormalized(sym))) Some(arg -> sym)
108-
else None
109-
}
110-
}
111-
112-
object WithSymbol {
113-
def unapply(arg: Tree): Option[(Tree, Symbol)] =
114-
sctx.symbol(arg.pos).map(x => arg -> x)
115-
}
116-
117-
val toGenericX = SymbolMatcher(
105+
val toGenericX = SymbolMatcher.normalized(
118106
Symbol("_root_.scala.collection.TraversableOnce.toMap.")
119107
)
120-
val toImmutableX = SymbolMatcher(
108+
val toImmutableX = SymbolMatcher.normalized(
121109
Symbol("_root_.scala.collection.TraversableOnce.toList."),
122110
Symbol("_root_.scala.collection.TraversableOnce.toSet.")
123111
)
124-
val toTpe = SymbolMatcher(
112+
val toTpe = SymbolMatcher.normalized(
125113
Symbol("_root_.scala.collection.TraversableLike.to.")
126114
)
127-
val iterator = SymbolMatcher(
115+
val iterator = SymbolMatcher.normalized(
128116
Symbol("_root_.scala.collection.LinearSeqLike.iterator."),
129117
Symbol("_root_.scala.collection.TraversableLike.toIterator.")
130118
)
131119

132-
def replaceToList(ctx: RewriteCtx) =
120+
def replaceToList(ctx: RuleCtx) =
133121
ctx.tree.collect {
134-
case iterator(n: Name, _) =>
135-
ctx.replaceTree(n, "iterator()")
136-
case toImmutableX(n: Name, s) =>
137-
ctx.replaceTree(n, s"to(strawman.collection.immutable.${s.name.stripPrefix("to")})")
138-
case toGenericX(n: Name, s) =>
139-
ctx.replaceTree(n, s"to(strawman.collection.${s.name.stripPrefix("to")})")
140-
case toTpe(n: Name, _) =>
141-
ctx.debug(n)
122+
case iterator(t: Name) =>
123+
ctx.replaceTree(t, "iterator()")
124+
case toImmutableX(t @ Name(n)) =>
125+
ctx.replaceTree(t, s"to(strawman.collection.immutable.${n.stripPrefix("to")})")
126+
case toGenericX(t @ Name(n)) =>
127+
ctx.replaceTree(t, s"to(strawman.collection.${n.stripPrefix("to")})")
128+
case toTpe(n: Name) =>
142129
(for {
143130
name <- n.tokens.lastOption
144-
_ = ctx.debug(name)
145131
open <- ctx.tokenList.find(name)(t => t.is[Token.LeftBracket])
146-
_ = ctx.debug(open)
147-
close <- ctx.matching.close(open.asInstanceOf[Token.LeftBracket])
148-
replacedTokens = ctx.tokenList.slice(open, close)
132+
close <- ctx.matchingParens.close(open.asInstanceOf[Token.LeftBracket])
149133
} yield
150134
ctx.replaceToken(open, "(") +
151135
ctx.replaceToken(close, ")")).getOrElse(Patch.empty)
152136
}.asPatch
153137

154-
def rewrite(ctx: RewriteCtx): Patch = {
138+
override def fix(ctx: RuleCtx): Patch = {
155139
replaceToList(ctx) +
156140
replaceSymbols(ctx) +
157141
replaceExtensionMethods(ctx) +

tests/src/test/scala/fix/Collectionstrawman_Tests.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@ import scalafix.testkit._
55
import scalafix._
66

77
class Collectionstrawman_Tests
8-
extends SemanticRewriteSuite(
9-
SemanticCtx.load(Classpath(AbsolutePath(BuildInfo.inputClassdirectory))),
8+
extends SemanticRuleSuite(
9+
SemanticdbIndex.load(Classpath(AbsolutePath(BuildInfo.inputClassdirectory))),
1010
AbsolutePath(BuildInfo.inputSourceroot),
1111
Seq(AbsolutePath(BuildInfo.outputSourceroot))
1212
) {

0 commit comments

Comments
 (0)