Skip to content

Commit 6873b92

Browse files
committed
Add scalafix migration rule.
Copied from https://github.com/scala/collection-strawman
2 parents d4c8c3b + 8b59395 commit 6873b92

13 files changed

+320
-0
lines changed

scalafix/build.sbt

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
def scalafixVersion = _root_.scalafix.Versions.version
2+
inScope(Global)(
3+
List(
4+
scalaVersion := _root_.scalafix.Versions.scala212
5+
)
6+
)
7+
8+
lazy val root = project
9+
.in(file("."))
10+
.aggregate(
11+
rules, input, output, tests
12+
)
13+
14+
lazy val rules = project.settings(
15+
libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % scalafixVersion
16+
)
17+
18+
lazy val input = project
19+
.settings(
20+
scalafixSourceroot := sourceDirectory.in(Compile).value
21+
)
22+
23+
lazy val output = project
24+
.settings(
25+
resolvers += "scala-pr" at "https://scala-ci.typesafe.com/artifactory/scala-integration/",
26+
scalaVersion := "2.13.0-M4-pre-20d3c21"
27+
)
28+
29+
lazy val tests = project
30+
.settings(
31+
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
32+
buildInfoPackage := "fix",
33+
buildInfoKeys := Seq[BuildInfoKey](
34+
"inputSourceroot" ->
35+
sourceDirectory.in(input, Compile).value,
36+
"outputSourceroot" ->
37+
sourceDirectory.in(output, Compile).value,
38+
"inputClassdirectory" ->
39+
classDirectory.in(input, Compile).value
40+
)
41+
)
42+
.dependsOn(input, rules)
43+
.enablePlugins(BuildInfoPlugin)
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/*
2+
rule = "scala:fix.Collectionstrawman_v0"
3+
*/
4+
package fix
5+
6+
object Collectionstrawman_v0_Stream {
7+
val s = Stream(1, 2, 3)
8+
s.append(List(4, 5, 6))
9+
1 #:: 2 #:: 3 #:: Stream.Empty
10+
val isEmpty: Stream[_] => Boolean = {
11+
case Stream.Empty => true
12+
case x #:: xs => false
13+
}
14+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
rule = "scala:fix.Collectionstrawman_v0"
3+
*/
4+
package fix
5+
6+
object Collectionstrawman_v0_Traversable {
7+
def foo(xs: Traversable[(Int, String)], ys: List[Int]): Unit = {
8+
xs.to[List]
9+
xs.to[Set]
10+
xs.toIterator
11+
ys.iterator
12+
}
13+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
rule = "scala:fix.Collectionstrawman_v0"
3+
*/
4+
package fix
5+
6+
import scala.language.postfixOps
7+
object Collectionstrawman_v0_Tuple2Zipped {
8+
def zipped(xs: List[Int], ys: List[Int]): Unit = {
9+
(xs, ys).zipped
10+
(xs,ys).zipped
11+
((xs, ys) zipped)
12+
(((xs) , (ys)).zipped)
13+
(xs, // foo
14+
ys).zipped
15+
/* a */(/* b */ xs /* c */, /* d */ ys /* e */)/* f */./* g */zipped/* h */
16+
(coll(1), coll(2)).zipped
17+
(List(1, 2, 3), Stream.from(1)).zipped
18+
}
19+
def coll(x: Int): List[Int] = ???
20+
}
21+
22+
object Collectionstrawman_v0_Tuple3Zipped {
23+
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
24+
(xs, ys, zs).zipped
25+
(xs,ys,zs).zipped
26+
((xs, ys, zs) zipped)
27+
(((xs) , (ys) , (zs)).zipped)
28+
(xs, // foo
29+
ys, // bar
30+
zs).zipped
31+
/* a */(/* b */ xs /* c */, /* d */ ys /* e */, /* f */ zs /* g */)/* h */./* i */zipped/* j */
32+
(coll(1), coll(2), coll(3)).zipped
33+
(List(1, 2, 3), Set(1, 2, 3), Stream.from(1)).zipped
34+
}
35+
def coll(x: Int): List[Int] = ???
36+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/*
2+
rule = "scala:fix.Collectionstrawman_v0"
3+
*/
4+
package fix
5+
6+
import scala.collection.mutable
7+
8+
class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {
9+
10+
xs.copyToBuffer(b)
11+
(xs ++ xs).copyToBuffer(b)
12+
13+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package fix
2+
3+
object Collectionstrawman_v0_Stream {
4+
val s = LazyList(1, 2, 3)
5+
s.lazyAppendAll(List(4, 5, 6))
6+
1 #:: 2 #:: 3 #:: LazyList.Empty
7+
val isEmpty: LazyList[_] => Boolean = {
8+
case LazyList.Empty => true
9+
case x #:: xs => false
10+
}
11+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package fix
2+
3+
object Collectionstrawman_v0_Traversable {
4+
def foo(xs: Iterable[(Int, String)], ys: List[Int]): Unit = {
5+
xs.to(List)
6+
xs.to(Set)
7+
xs.iterator()
8+
ys.iterator()
9+
}
10+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package fix
2+
3+
import scala.language.postfixOps
4+
object Collectionstrawman_v0_Tuple2Zipped {
5+
def zipped(xs: List[Int], ys: List[Int]): Unit = {
6+
xs.lazyZip(ys)
7+
xs.lazyZip(ys)
8+
(xs.lazyZip(ys) )
9+
((xs).lazyZip((ys)))
10+
xs.lazyZip(// foo
11+
ys)
12+
/* a *//* b */ xs /* c */.lazyZip(/* d */ ys /* e */)/* f *//* g *//* h */
13+
coll(1).lazyZip(coll(2))
14+
List(1, 2, 3).lazyZip(LazyList.from(1))
15+
}
16+
def coll(x: Int): List[Int] = ???
17+
}
18+
19+
object Collectionstrawman_v0_Tuple3Zipped {
20+
def zipped(xs: List[Int], ys: List[Int], zs: List[Int]): Unit = {
21+
xs.lazyZip(ys).lazyZip(zs)
22+
xs.lazyZip(ys).lazyZip(zs)
23+
(xs.lazyZip(ys).lazyZip(zs) )
24+
((xs).lazyZip((ys)).lazyZip((zs)))
25+
xs.lazyZip(// foo
26+
ys).lazyZip(// bar
27+
zs)
28+
/* a *//* b */ xs /* c */.lazyZip(/* d */ ys /* e */).lazyZip(/* f */ zs /* g */)/* h *//* i *//* j */
29+
coll(1).lazyZip(coll(2)).lazyZip(coll(3))
30+
List(1, 2, 3).lazyZip(Set(1, 2, 3)).lazyZip(LazyList.from(1))
31+
}
32+
def coll(x: Int): List[Int] = ???
33+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package fix
2+
3+
import scala.collection.mutable
4+
5+
class Collectionstrawman_v0_copyToBuffer(xs: List[Int], b: mutable.Buffer[Int]) {
6+
7+
b ++= xs
8+
b ++= xs ++ xs
9+
10+
}

scalafix/project/build.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sbt.version=0.13.16

0 commit comments

Comments
 (0)