Skip to content

Commit

Permalink
Merge pull request #159 from olafurpg/scalafix-0.9
Browse files Browse the repository at this point in the history
Upgrade to scalafix v0.9.0
  • Loading branch information
julienrf committed Oct 19, 2018
2 parents 7b635e7 + ca7b990 commit 40688b9
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 27 deletions.
57 changes: 35 additions & 22 deletions README.md
Expand Up @@ -38,45 +38,58 @@ The library also adds backported versions of new collection types, currently `sc

## Migration Tool

We created two migration rules:

* `Collection213Upgrade` For upgrading applications (like web server, etc) from 2.11/2.12 to 2.13
* `Collection213CrossCompat` For library that wants to cross compile to 2.11, 2.12 and 2.13
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).

```scala
// project/plugins.sbt

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.7.0-RC1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.0")
```

### Collection213Upgrade

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.

```scala
// build.sbt or project/Build.scala
// build.sbt
scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "0.2.1"
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
```

// If you are using project/Build.scala add the following imports:
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}
```bash
// sbt shell
> ;test:scalafix Collections213Upgrade ;scalafix Collections213Upgrade
```

### Collections213CrossCompat

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

libraryDependencies += collectionCompat // required for Collection213CrossCompat
addCompilerPlugin(scalafixSemanticdb)
scalacOptions ++= List(
"-Yrangepos",
"-Ywarn-unused-import",
"-P:semanticdb:synthetics:on"
)
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.

scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % Dependencies.collectionCompatVersion
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.

```scala
// build.sbt
scalafixDependencies += "org.scala-lang.modules" %% "scala-collection-migrations" % "0.2.1"
libraryDependencies += "org.scala-lang.modules" %% "scala-collection-compat" % "0.2.1"
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on")
```

Then run:

```bash
> ;scalafix Collection213Upgrade ;test:scalafix Collection213Upgrade # For Applications
# or
> ;scalafix Collection213CrossCompat ;test:scalafix Collection213CrossCompat # For Libraries
// sbt shell
> ;test:scalafix Collections213CrossCompat ;scalafix Collections213CrossCompat
```

### Build.scala

```scala
// If you are using project/Build.scala add the following imports:
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}
```

### Contributing

The migration tool is not exhaustive and we will continue to improve
it over time. If you encounter a use case that’s not supported, please
report it as described in the
Expand Down
4 changes: 0 additions & 4 deletions build.sbt
Expand Up @@ -162,10 +162,6 @@ lazy val `scalafix-data` = MultiScalaProject(
"scalafix/data",
_.settings(sharedScalafixSettings)
.settings(dontPublish)
.settings(
addCompilerPlugin(scalafixSemanticdb),
scalacOptions += "-P:semanticdb:synthetics:on"
)
)

val `scalafix-data211` = `scalafix-data`(scala211, _.dependsOn(compat211JVM))
Expand Down
2 changes: 1 addition & 1 deletion project/plugins.sbt
Expand Up @@ -10,7 +10,7 @@ val scalaJSVersion = Option(System.getenv("SCALAJS_VERSION")).filter(_.nonEmpty)
addSbtPlugin("org.scala-js" % "sbt-scalajs" % scalaJSVersion)
addSbtPlugin("org.portable-scala" % "sbt-scalajs-crossproject" % "0.6.0")
addSbtPlugin("org.scala-lang.modules" % "sbt-scala-module" % "1.0.14")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.7.0-RC1")
addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.0")
addSbtPlugin("com.eed3si9n" % "sbt-buildinfo" % "0.7.0")
addSbtPlugin("com.typesafe.sbt" % "sbt-pgp" % "0.8.3")

Expand Down

0 comments on commit 40688b9

Please sign in to comment.