Skip to content

Commit 746a7de

Browse files
authored
Merge pull request #154 from MasseGuillaume/scalafix-0.6
Scalafix 0.6
2 parents dfdc979 + 0e93c26 commit 746a7de

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

52 files changed

+641
-530
lines changed

.travis.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,9 @@ matrix:
7676
# | oraclejdk8 | 2.13.0-M5 | js | 0.6.23 | |
7777
# | oraclejdk8 | 2.12.6 | jvm | | true |
7878

79-
before_script: ./checkCLA.sh
79+
before_script:
80+
- admin/checkCLA.sh
81+
8082
script:
8183
- java -version
8284
- sbt ci

README.md

Lines changed: 39 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ This library provides some of the new APIs from Scala 2.13 to Scala 2.11 and 2.1
88
To use this library, add the following to your build.sbt:
99

1010
```
11-
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "0.2.0"
11+
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "0.2.1"
1212
```
1313

14-
Version 0.2.0 is compatible with Scala 2.13.0-M5. For Scala 2.13.0-M4 you should use version 0.1.1.
14+
Version 0.2.1 is compatible with Scala 2.13.0-M5. For Scala 2.13.0-M4 you should use version 0.1.1.
1515

1616
Note that there are multiple ways to cross-build projects, see https://github.com/scala/collection-strawman/wiki/FAQ#how-do-i-cross-build-my-project-against-scala-212-and-scala-213.
1717

@@ -34,17 +34,48 @@ With this compatibility library you can also use the 2.13 syntax which uses a co
3434
The 2.13 version consists only of an empty `scala.collection.compat` package object that allows you to write `import scala.collection.compat._` in 2.13.
3535
The 2.11/2.12 version has the compatibility extensions in this package.
3636

37-
3837
The library also adds backported versions of new collection types, currently `scala.collection.compat.immutable.ArraySeq`. In 2.11/2.12, this type is a new collection implementation. In 2.13, it is an alias for `scala.collection.immutable.ArraySeq`.
3938

4039
## Migration Tool
4140

42-
A tool is being developed to automatically migrate code that uses the standard
43-
collection to use the strawman.
41+
We created two migration rules:
42+
43+
* `Collection213Upgrade` For upgrading applications (like web server, etc) from 2.11/2.12 to 2.13
44+
* `Collection213CrossCompat` For library that wants to cross compile to 2.11, 2.12 and 2.13
45+
46+
```scala
47+
// project/plugins.sbt
48+
49+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.7.0-RC1")
50+
```
51+
52+
```scala
53+
// build.sbt or project/Build.scala
4454

45-
To use it, add the [scalafix](https://scalacenter.github.io/scalafix/) sbt plugin
46-
to your build, as explained in
47-
[its documentation](https://scalacenter.github.io/scalafix/#Installation).
55+
// If you are using project/Build.scala add the following imports:
56+
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}
57+
58+
val collectionCompatVersion = "0.2.1"
59+
val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % collectionCompatVersion
60+
61+
libraryDependencies += collectionCompat // required for Collection213CrossCompat
62+
addCompilerPlugin(scalafixSemanticdb)
63+
scalacOptions ++= List(
64+
"-Yrangepos",
65+
"-Ywarn-unused-import",
66+
"-P:semanticdb:synthetics:on"
67+
)
68+
69+
scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % Dependencies.collectionCompatVersion
70+
```
71+
72+
Then run:
73+
74+
```bash
75+
> ;scalafix Collection213Upgrade ;test:scalafix Collection213Upgrade # For Applications
76+
# or
77+
> ;scalafix Collection213CrossCompat ;test:scalafix Collection213CrossCompat # For Libraries
78+
```
4879

4980
The migration tool is not exhaustive and we will continue to improve
5081
it over time. If you encounter a use case that’s not supported, please
File renamed without changes.

build.sbt

Lines changed: 34 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import ScalaModulePlugin._
22
import sbtcrossproject.{crossProject, CrossType}
3-
import _root_.scalafix.Versions.{version => scalafixVersion, scala212 => scalafixScala212}
3+
import _root_.scalafix.sbt.BuildInfo.{scalafixVersion, scala212 => scalafixScala212}
44

55
lazy val root = project
66
.in(file("."))
@@ -157,10 +157,16 @@ lazy val sharedScalafixSettings = Seq(
157157
)
158158

159159
// common part between input/output
160-
lazy val `scalafix-data` = MultiScalaProject("scalafix-data",
161-
"scalafix/data",
162-
_.settings(sharedScalafixSettings)
163-
.settings(dontPublish))
160+
lazy val `scalafix-data` = MultiScalaProject(
161+
"scalafix-data",
162+
"scalafix/data",
163+
_.settings(sharedScalafixSettings)
164+
.settings(dontPublish)
165+
.settings(
166+
addCompilerPlugin(scalafixSemanticdb),
167+
scalacOptions += "-P:semanticdb:synthetics:on"
168+
)
169+
)
164170

165171
val `scalafix-data211` = `scalafix-data`(scala211, _.dependsOn(compat211JVM))
166172
val `scalafix-data212` = `scalafix-data`(scalafixScala212, _.dependsOn(compat212JVM))
@@ -173,7 +179,11 @@ lazy val `scalafix-input` = project
173179
.settings(dontPublish)
174180
.settings(
175181
scalaVersion := scalafixScala212,
176-
scalafixSourceroot := sourceDirectory.in(Compile).value
182+
addCompilerPlugin(scalafixSemanticdb),
183+
scalacOptions ++= Seq(
184+
"-Yrangepos",
185+
"-P:semanticdb:synthetics:on"
186+
)
177187
)
178188
.dependsOn(`scalafix-data212`)
179189

@@ -183,15 +193,20 @@ val `scalafix-output` = MultiScalaProject("scalafix-output",
183193
.settings(dontPublish)
184194
.disablePlugins(ScalafixPlugin))
185195

186-
lazy val output212 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212/src/main")
187-
lazy val addOutput212 = unmanagedSourceDirectories in Compile += output212.value / "scala"
196+
lazy val outputCross =
197+
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output/src/main/scala")
198+
199+
lazy val output212 =
200+
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212/src/main/scala")
201+
lazy val addOutput212 = unmanagedSourceDirectories in Compile += output212.value
188202

189203
lazy val output212Plus =
190-
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212+/src/main")
191-
lazy val addOutput212Plus = unmanagedSourceDirectories in Compile += output212Plus.value / "scala"
204+
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output212+/src/main/scala")
205+
lazy val addOutput212Plus = unmanagedSourceDirectories in Compile += output212Plus.value
192206

193-
lazy val output213 = Def.setting((baseDirectory in ThisBuild).value / "scalafix/output213/src/main")
194-
lazy val addOutput213 = unmanagedSourceDirectories in Compile += output213.value / "scala"
207+
lazy val output213 =
208+
Def.setting((baseDirectory in ThisBuild).value / "scalafix/output213/src/main/scala")
209+
lazy val addOutput213 = unmanagedSourceDirectories in Compile += output213.value
195210

196211
lazy val `scalafix-output211` = `scalafix-output`(
197212
scala211,
@@ -226,28 +241,15 @@ lazy val `scalafix-tests` = project
226241
.settings(
227242
scalaVersion := scalafixScala212,
228243
libraryDependencies += "ch.epfl.scala" % "scalafix-testkit" % scalafixVersion % Test cross CrossVersion.full,
229-
buildInfoPackage := "build",
230-
buildInfoKeys := Seq[BuildInfoKey](
231-
"inputSourceroot" -> sourceDirectory.in(`scalafix-input`, Compile).value,
232-
"outputSourceroot" -> (baseDirectory in ThisBuild).value / "scalafix/output/src/main",
233-
"output212Sourceroot" -> output212.value,
234-
"output212PlusSourceroot" -> output212Plus.value,
235-
"output213Sourceroot" -> output213.value,
236-
"output213FailureSourceroot" -> sourceDirectory
237-
.in(`scalafix-output213-failure`, Compile)
238-
.value,
239-
"inputClassdirectory" -> classDirectory.in(`scalafix-input`, Compile).value
240-
),
241-
test in Test := (test in Test)
242-
.dependsOn(
243-
compile in (`scalafix-output211`, Compile),
244-
compile in (`scalafix-output212`, Compile),
245-
compile in (`scalafix-output213`, Compile)
246-
)
247-
.value
244+
scalafixTestkitOutputSourceDirectories := Seq(outputCross.value,
245+
output212.value,
246+
output212Plus.value,
247+
output213.value),
248+
scalafixTestkitInputSourceDirectories := sourceDirectories.in(`scalafix-input`, Compile).value,
249+
scalafixTestkitInputClasspath := fullClasspath.in(`scalafix-input`, Compile).value
248250
)
249251
.dependsOn(`scalafix-input`, `scalafix-rules`)
250-
.enablePlugins(BuildInfoPlugin)
252+
.enablePlugins(BuildInfoPlugin, ScalafixTestkitPlugin)
251253

252254
lazy val dontPublish = Seq(
253255
publishArtifact := false,

project/plugins.sbt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ else
88
val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty).getOrElse("0.6.25")
99

1010
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
11-
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.5.0")
11+
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
1212
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
13-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.5.10")
13+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.7.0-RC1")
1414
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
1515
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
1616

scalafix/input/src/main/scala/fix/BreakoutSrc.scala

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

@@ -103,4 +103,9 @@ class BreakoutSrc(ts: Traversable[Int], vec: Vector[Int], list: List[Int], seq:
103103
List(1 -> "1").map(x => x)(breakOut): immutable.IntMap[String]
104104
List(1L -> "1").map(x => x)(breakOut): immutable.LongMap[String]
105105
List(1L -> "1").map(x => x)(breakOut): mutable.LongMap[String]
106+
List(1).map(x => x)(breakOut): collection.BitSet
107+
108+
109+
List(1).map(x => x)(collection.breakOut): Vector[Int]
110+
List(1).map(x => x)(collection.breakOut): immutable.SortedSet[Int]
106111
}

scalafix/input/src/main/scala/fix/BreakoutSrc212Plus.scala

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

scalafix/input/src/main/scala/fix/CanBuildFromNegSrc213Failure.scala

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

scalafix/input/src/main/scala/fix/CanBuildFromSrc.scala

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

66
import scala.language.higherKinds
77

8+
import scala.collection.immutable
89
import collection.generic.CanBuildFrom
910

1011
object CanBuildFromSrc {
@@ -37,6 +38,9 @@ object CanBuildFromSrc {
3738
def f2[T, That](implicit cbf: CanBuildFrom[Nothing, T, That]): Foo[T, That] =
3839
new Foo
3940

41+
def f3[T, That](implicit cbf: CanBuildFrom[Nothing, T, That with immutable.Traversable[_]]): Foo[T, That] =
42+
new Foo
43+
4044
class Foo[T, That](implicit cbf: CanBuildFrom[Nothing, T, That]) {
4145
val b = cbf()
4246
}
Lines changed: 32 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,42 @@
11
/*
2-
rule = "scala:fix.CrossCompat"
2+
rule = "Collection213CrossCompat"
33
*/
44
package fix
55

6-
import scala.collection.immutable
7-
import scala.collection.mutable
6+
import scala.{collection => c}
7+
import scala.collection.{immutable => i, mutable => m}
88

99
object CompanionSrc {
1010

11-
(null: collection.IndexedSeq[Int]).companion
12-
(null: collection.Iterable[Int]).companion
13-
(null: collection.Seq[Int]).companion
14-
(null: collection.Traversable[Int]).companion
11+
(null: c.IndexedSeq[Int]).companion
12+
(null: c.Iterable[Int]).companion
13+
(null: c.Seq[Int]).companion
14+
(null: c.Traversable[Int]).companion
1515

16-
(null: immutable.HashSet[Int]).companion
17-
(null: immutable.IndexedSeq[Int]).companion
18-
(null: immutable.Iterable[Int]).companion
19-
(null: immutable.LinearSeq[Int]).companion
20-
(null: immutable.List[Int]).companion
21-
(null: immutable.ListSet[Int]).companion
22-
(null: immutable.Queue[Int]).companion
23-
(null: immutable.Seq[Int]).companion
24-
(null: immutable.Set[Int]).companion
25-
(null: immutable.Stream[Int]).companion
26-
(null: immutable.Traversable[Int]).companion
27-
(null: immutable.Vector[Int]).companion
16+
(null: i.HashSet[Int]).companion
17+
(null: i.IndexedSeq[Int]).companion
18+
(null: i.Iterable[Int]).companion
19+
(null: i.LinearSeq[Int]).companion
20+
(null: i.List[Int]).companion
21+
(null: i.ListSet[Int]).companion
22+
(null: i.Queue[Int]).companion
23+
(null: i.Seq[Int]).companion
24+
(null: i.Set[Int]).companion
25+
(null: i.Stream[Int]).companion
26+
(null: i.Traversable[Int]).companion
27+
(null: i.Vector[Int]).companion
2828

29-
(null: mutable.ArrayBuffer[Int]).companion
30-
(null: mutable.ArraySeq[Int]).companion
31-
(null: mutable.ArrayStack[Int]).companion
32-
(null: mutable.Buffer[Int]).companion
33-
(null: mutable.HashSet[Int]).companion
34-
(null: mutable.IndexedSeq[Int]).companion
35-
(null: mutable.Iterable[Int]).companion
36-
(null: mutable.LinearSeq[Int]).companion
37-
(null: mutable.LinkedHashSet[Int]).companion
38-
(null: mutable.Queue[Int]).companion
39-
(null: mutable.Seq[Int]).companion
40-
(null: mutable.Set[Int]).companion
41-
(null: mutable.Traversable[Int]).companion
29+
(null: m.ArrayBuffer[Int]).companion
30+
(null: m.ArraySeq[Int]).companion
31+
(null: m.ArrayStack[Int]).companion
32+
(null: m.Buffer[Int]).companion
33+
(null: m.HashSet[Int]).companion
34+
(null: m.IndexedSeq[Int]).companion
35+
(null: m.Iterable[Int]).companion
36+
(null: m.LinearSeq[Int]).companion
37+
(null: m.LinkedHashSet[Int]).companion
38+
(null: m.Queue[Int]).companion
39+
(null: m.Seq[Int]).companion
40+
(null: m.Set[Int]).companion
41+
(null: m.Traversable[Int]).companion
4242
}

0 commit comments

Comments
 (0)