Skip to content

Commit 40688b9

Browse files
authored
Merge pull request #159 from olafurpg/scalafix-0.9
Upgrade to scalafix v0.9.0
2 parents 7b635e7 + ca7b990 commit 40688b9

File tree

3 files changed

+36
-27
lines changed

3 files changed

+36
-27
lines changed

README.md

+35-22
Original file line numberDiff line numberDiff line change
@@ -38,45 +38,58 @@ The library also adds backported versions of new collection types, currently `sc
3838

3939
## Migration Tool
4040

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
41+
The migration rules use scalafix. Please see the [official installation instruction](https://scalacenter.github.io/scalafix/docs/users/installation.html) and, in particular, check that your full Scala version is supported (ex 2.12.6).
4542

4643
```scala
4744
// project/plugins.sbt
4845

49-
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.7.0-RC1")
46+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.0")
5047
```
5148

49+
### Collection213Upgrade
50+
51+
The `Collection213Upgrade` rewrite upgrades to the 2.13 collections without the ability to compile the code-base with 2.12 or 2.11. This rewrite is suitable for applications that don't need to cross-compile against multiple Scala versions.
52+
5253
```scala
53-
// build.sbt or project/Build.scala
54+
// build.sbt
55+
scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "0.2.1"
56+
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
57+
```
5458

55-
// If you are using project/Build.scala add the following imports:
56-
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}
59+
```bash
60+
// sbt shell
61+
> ;test:scalafix Collections213Upgrade ;scalafix Collections213Upgrade
62+
```
63+
64+
### Collections213CrossCompat
5765

58-
val collectionCompatVersion = "0.2.1"
59-
val collectionCompat = "org.scala-lang.modules" %% "scala-collection-compat" % collectionCompatVersion
6066

61-
libraryDependencies += collectionCompat // required for Collection213CrossCompat
62-
addCompilerPlugin(scalafixSemanticdb)
63-
scalacOptions ++= List(
64-
"-Yrangepos",
65-
"-Ywarn-unused-import",
66-
"-P:semanticdb:synthetics:on"
67-
)
67+
The `Collections213CrossCompat` rewrite upgrades to the 2.13 collections with the ability to compile the code-base with 2.12 or later. This rewrite is suitable for libraries that are cross-published for multiple Scala versions.
6868

69-
scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % Dependencies.collectionCompatVersion
69+
To cross-build for 2.12 and 2.11, the rewrite rule introduces a dependency on the scala-collection-compat module, which provides the syntax of 2.13 on 2.12 and 2.11. This enables you to write your library using the latest 2.13 collections API while still supporting users on an older Scala version.
70+
71+
```scala
72+
// build.sbt
73+
scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "0.2.1"
74+
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "0.2.1"
75+
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
7076
```
7177

72-
Then run:
7378

7479
```bash
75-
> ;scalafix Collection213Upgrade ;test:scalafix Collection213Upgrade # For Applications
76-
# or
77-
> ;scalafix Collection213CrossCompat ;test:scalafix Collection213CrossCompat # For Libraries
80+
// sbt shell
81+
> ;test:scalafix Collections213CrossCompat ;scalafix Collections213CrossCompat
7882
```
7983

84+
### Build.scala
85+
86+
```scala
87+
// If you are using project/Build.scala add the following imports:
88+
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}
89+
```
90+
91+
### Contributing
92+
8093
The migration tool is not exhaustive and we will continue to improve
8194
it over time. If you encounter a use case that’s not supported, please
8295
report it as described in the

build.sbt

-4
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,6 @@ lazy val `scalafix-data` = MultiScalaProject(
162162
"scalafix/data",
163163
_.settings(sharedScalafixSettings)
164164
.settings(dontPublish)
165-
.settings(
166-
addCompilerPlugin(scalafixSemanticdb),
167-
scalacOptions += "-P:semanticdb:synthetics:on"
168-
)
169165
)
170166

171167
val `scalafix-data211` = `scalafix-data`(scala211, _.dependsOn(compat211JVM))

project/plugins.sbt

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty)
1010
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
1111
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.7.0-RC1")
13+
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.0")
1414
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
1515
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")
1616

0 commit comments

Comments
 (0)