File tree Expand file tree Collapse file tree 2 files changed +21
-9
lines changed
rewrites/src/main/scala/fix/scala213 Expand file tree Collapse file tree 2 files changed +21
-9
lines changed Original file line number Diff line number Diff line change @@ -15,27 +15,26 @@ inThisBuild(List(
1515 semanticdbEnabled := true ,
1616 semanticdbOptions += " -P:semanticdb:synthetics:on" , // make sure to add this
1717 semanticdbVersion := scalafixSemanticdb.revision,
18+ scalafixScalaBinaryVersion := CrossVersion .binaryScalaVersion(scalaVersion.value),
1819))
1920```
2021
2122Then run the desired rewrite(s) ([ official docs] [ 2 ] ), in sbt:
2223
2324``` scala
24- > scalafix dependency: fix.scala213.ExplicitNonNullaryApply @ org.scala- lang: scala- rewrites: 0.1.0
25- > Test / scalafix dependency: fix.scala213.ExplicitNonNullaryApply @ org.scala- lang: scala- rewrites: 0.1.0
25+ > scalafixAll dependency: fix.scala213.ExplicitNonNullaryApply @ org.scala- lang: scala- rewrites: 0.1.1
2626```
2727
2828You can also add the following to your ` build.sbt ` :
2929
3030``` scala
31- ThisBuild / scalafixDependencies += " org.scala-lang" %% " scala-rewrites" % " 0.1.0 "
31+ ThisBuild / scalafixDependencies += " org.scala-lang" %% " scala-rewrites" % " 0.1.1 "
3232```
3333
3434and then:
3535
3636``` scala
37- > scalafix fix.scala213.ExplicitNonNullaryApply
38- > Test / scalafix fix.scala213.ExplicitNonNullaryApply
37+ > scalafixAll fix.scala213.ExplicitNonNullaryApply
3938```
4039
4140[ 1 ] : https://scalacenter.github.io/scalafix/docs/users/installation.html
Original file line number Diff line number Diff line change @@ -94,10 +94,23 @@ final class ExplicitNonNullaryApply(global: LazyValue[ScalafixGlobal])
9494 case Type .Select (_, name : Type .Name ) => name
9595 }
9696
97- override def withConfiguration (config : Configuration ) =
98- Configured .ok(new ExplicitNonNullaryApply (LazyValue .later { () =>
99- ScalafixGlobal .newCompiler(config.scalacClasspath, config.scalacOptions, Map .empty)
100- }))
97+ override def withConfiguration (config : Configuration ) = {
98+ val compileSv = config.scalaVersion
99+ val runtimeSv = scala.util.Properties .versionNumberString
100+ if ((compileSv.take(4 ) != runtimeSv.take(4 )) && config.scalacOptions.nonEmpty) {
101+ Configured .error(
102+ s " Scala version mismatch: " +
103+ s " (1) the target sources were compiled with Scala $compileSv; " +
104+ s " (2) Scalafix is running on Scala $runtimeSv. " +
105+ s " To fix make scalafixScalaBinaryVersion == ${compileSv.take(4 )}. " +
106+ " Try `ThisBuild / scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value)`."
107+ )
108+ } else {
109+ Configured .ok(new ExplicitNonNullaryApply (LazyValue .later { () =>
110+ ScalafixGlobal .newCompiler(config.scalacClasspath, config.scalacOptions, Map .empty)
111+ }))
112+ }
113+ }
101114
102115 override def afterComplete () = shutdownCompiler()
103116 def shutdownCompiler () = for (g <- global) nonFatalCatch { g.askShutdown(); g.close() }
You can’t perform that action at this time.
0 commit comments