Skip to content

Instantly share code, notes, and snippets.

@japgolly japgolly/upgrade.md
Last active Sep 9, 2019

Embed
What would you like to do?
Scala 2.13 migration notes

scalafix

addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % "0.9.6")
import scalafix.sbt.ScalafixPlugin.autoImport.{scalafixDependencies, scalafixSemanticdb}

scalafixDependencies in ThisBuild += "org.scala-lang.modules" %% "scala-collection-migrations" % "2.1.1",
libraryDependencies +=  "org.scala-lang.modules" %% "scala-collection-compat" % "2.1.2",
scalacOptions ++= List("-Yrangepos", "-P:semanticdb:synthetics:on"),
;scalafixEnable ;test:scalafix Collection213CrossCompat ;scalafix Collection213CrossCompat
git add -A && git stash && git stash apply && git co project && git st
git commit -m 'Run Collection213CrossCompat scalafix'

Scala 2.13

for f in $(seq 23); do find . -type f -name '*.scala' -exec perl -pi -e 's/^([^"]+?)→/\1->/g; s/^([^"]+?)←/\1<-/g; s/^([^"]+?)⇒/\1=>/g' {} +; done
find . -type f -name '*.scala' -exec perl -pi -e '
    s/\b(?:Gen)?Traversable/Iterable/g;
    s/\\033/\\u001b/g
  ' {} +

utest

find . -type f -path '*/test/*.scala' -exec perl -pi -e '
    s/^( *)'"'"'([^ ]+)\{/\1"\2" - {/;
    s/^( *)'"'"'([^ ]+)( +)(?:- *)?\{/\1"\2"\3- {/;
    s/^( *)'"'"'([^ ]+)( +)-/\1"\2"\3-/;
    s/^(\s+)(?:override +)(?:val|def) +tests += +TestSuite *{ *$/\1override def tests = Tests {/;
  ' {} +

SBT config for macro annotations

  def byScalaVersion[A](f: PartialFunction[(Long, Long), Seq[A]]): Def.Initialize[Seq[A]] =
    Def.setting(CrossVersion.partialVersion(scalaVersion.value).flatMap(f.lift).getOrElse(Nil))

  def addMacroParadisePlugin = Def.settings(
    Seq(
      libraryDependencies ++= byScalaVersion {
        case (2, 12) => Seq(compilerPlugin("org.scalamacros" % "paradise" % Ver.MacroParadise cross CrossVersion.patch))
        case (2, 13) => Nil
      }.value,
      scalacOptions ++= byScalaVersion {
        case (2, 12) => Nil
        case (2, 13) => Seq("-Ymacro-annotations")
      }.value
    ))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.