diff --git a/project/Dependencies.scala b/project/Dependencies.scala index f36b5cf3..1dc237c8 100644 --- a/project/Dependencies.scala +++ b/project/Dependencies.scala @@ -2,7 +2,7 @@ import sbt._ object Dependencies { val x = List(1) // scalafix:ok - def scalafixVersion: String = "0.10.4" + def scalafixVersion: String = "0.10.4+78-f6b8c84d-SNAPSHOT" val all = List( "org.eclipse.jgit" % "org.eclipse.jgit" % "5.13.1.202206130422-r", diff --git a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala index e8b05dcf..1a31a795 100644 --- a/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala +++ b/src/main/scala/scalafix/internal/sbt/ScalafixInterface.scala @@ -129,6 +129,11 @@ object ScalafixInterface { "Rules such as ExplicitResultTypes requiring the project version to match the Scalafix " + "version are unsupported for the moment." ) + else if (scalafixBinaryScalaVersion == "2.11") + logger.error( + "Scala 2.11 is no longer supported. Please downgrade to the final version supporting " + + "it: sbt-scalafix 0.10.4." + ) val callback = new ScalafixLogger(logger) val scalafixArguments = ScalafixAPI .fetchAndClassloadInstance( diff --git a/src/main/scala/scalafix/sbt/BuildInfo.scala b/src/main/scala/scalafix/sbt/BuildInfo.scala index 24ee3cea..1ebf6b3b 100644 --- a/src/main/scala/scalafix/sbt/BuildInfo.scala +++ b/src/main/scala/scalafix/sbt/BuildInfo.scala @@ -14,10 +14,10 @@ object BuildInfo { property("scala213") def scala212: String = property("scala212") - def scala211: String = - property("scala211") + @deprecated("Scala 2.11 is no longer supported", ">0.10.4") + def scala211: String = ??? def supportedScalaVersions: List[String] = - List(scala213, scala212, scala211) + List(scala213, scala212) private val propertiesPath = "scalafix-interfaces.properties" diff --git a/src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala index 2b2fc9da..9a5dc63b 100644 --- a/src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixTestkitPlugin.scala @@ -33,7 +33,7 @@ object ScalafixTestkitPlugin extends AutoPlugin { // This makes it simpler to use sbt-scalafix SNAPSHOTS: such snapshots may bring scalafix-* SNAPSHOTS which is fine in the // meta build as the same resolver (declared in project/plugins.sbt) is used. However, since testkit-enabled projects are // built against a version of scalafix-testkit dictated by scalafix.sbt.BuildInfo.scalafixVersion, the same resolver is - // needed here as well. + // needed here as well. Unfortunately it works only for sbt 1.7+, see https://github.com/sbt/sbt/pull/6849. includePluginResolvers := true ) diff --git a/src/sbt-test/sbt-1.5/scalafixEnable/build.sbt b/src/sbt-test/sbt-1.5/scalafixEnable/build.sbt index 87a40fc0..e24f2b0c 100644 --- a/src/sbt-test/sbt-1.5/scalafixEnable/build.sbt +++ b/src/sbt-test/sbt-1.5/scalafixEnable/build.sbt @@ -9,7 +9,13 @@ lazy val scala210 = project lazy val scala211 = project .in(file("scala211")) .settings( - scalaVersion := "2.11.12" // supported by semanticdb-scalac + scalaVersion := "2.11.12" // supported by semanticdb-scalac, but not by sbt-scalafix + ) + +lazy val scala212 = project + .in(file("scala212")) + .settings( + scalaVersion := "2.12.17" // supported by semanticdb-scalac ) lazy val scala3 = project diff --git a/src/sbt-test/sbt-scalafix/cross-build/scala210/src/main/scala/Main.scala b/src/sbt-test/sbt-1.5/scalafixEnable/scala212/src/main/scala/Main.scala similarity index 100% rename from src/sbt-test/sbt-scalafix/cross-build/scala210/src/main/scala/Main.scala rename to src/sbt-test/sbt-1.5/scalafixEnable/scala212/src/main/scala/Main.scala diff --git a/src/sbt-test/sbt-1.5/scalafixEnable/test b/src/sbt-test/sbt-1.5/scalafixEnable/test index 46297c3d..3deb3b46 100644 --- a/src/sbt-test/sbt-1.5/scalafixEnable/test +++ b/src/sbt-test/sbt-1.5/scalafixEnable/test @@ -1,13 +1,14 @@ # enable semanticdb output where supported > scalafixEnable -# check that projects not supported by semanticdb-scalac can still compile +# check that projects not supported by sbt-scalafix can still compile > scala210/compile +> scala211/compile -# check that we can run a semantic rule against a Scala 2.11 dialect source file --> scala211/scalafix --check SemanticRule -> scala211/scalafix SemanticRule -> scala211/scalafix --check SemanticRule +# check that we can run a semantic rule against a Scala 2.12 dialect source file +-> scala212/scalafix --check SemanticRule +> scala212/scalafix SemanticRule +> scala212/scalafix --check SemanticRule # check that we can run a semantic rule against a Scala 3 dialect source file -> scala3/scalafix --check SemanticRule diff --git a/src/sbt-test/sbt-1.5/testkit/build.sbt b/src/sbt-test/sbt-1.5/testkit/build.sbt index 3c6733c1..ec5eb4e9 100644 --- a/src/sbt-test/sbt-1.5/testkit/build.sbt +++ b/src/sbt-test/sbt-1.5/testkit/build.sbt @@ -1,12 +1,14 @@ lazy val V = _root_.scalafix.sbt.BuildInfo -lazy val rulesCrossVersions = Seq(V.scala213, V.scala212, V.scala211) +lazy val rulesCrossVersions = Seq(V.scala213, V.scala212) lazy val scala3Version = "3.0.0" inThisBuild( List( semanticdbEnabled := true, - semanticdbVersion := scalafixSemanticdb.revision + semanticdbVersion := scalafixSemanticdb.revision, + // need for sbt <1.7.0 as includePluginResolvers has no effect, see https://github.com/sbt/sbt/pull/6853 + resolvers += Resolver.sonatypeRepo("public") ) ) @@ -26,7 +28,7 @@ lazy val input = projectMatrix scalacOptions += "-Xsource:3" ) ) - .jvmPlatform(scalaVersions = Seq(V.scala212, V.scala211)) + .jvmPlatform(scalaVersions = Seq(V.scala212)) lazy val output = projectMatrix .defaultAxes(VirtualAxis.jvm) @@ -71,10 +73,5 @@ lazy val tests = projectMatrix axisValues = Seq(TargetAxis(V.scala212), VirtualAxis.jvm), settings = Seq() ) - .customRow( - scalaVersions = Seq(V.scala211), - axisValues = Seq(TargetAxis(V.scala211), VirtualAxis.jvm), - settings = Seq() - ) .dependsOn(rules) .enablePlugins(ScalafixTestkitPlugin) diff --git a/src/sbt-test/sbt-scalafix/cross-build/build.sbt b/src/sbt-test/sbt-scalafix/cross-build/build.sbt index e73822da..a8d0e1f8 100644 --- a/src/sbt-test/sbt-scalafix/cross-build/build.sbt +++ b/src/sbt-test/sbt-scalafix/cross-build/build.sbt @@ -16,19 +16,10 @@ lazy val root = project .in(file(".")) .aggregate( javaProject, - scala211, - scala210, scala212, scala213 ) -lazy val scala210 = project.settings( - scalaVersion := "2.10.7" -) -lazy val scala211 = project.settings( - scalaVersion := Versions.scala211, - scalafixSettings -) lazy val scala212 = project .configs(IntegrationTest) .settings( diff --git a/src/sbt-test/sbt-scalafix/cross-build/scala210/src/test/scala/MainTest.scala b/src/sbt-test/sbt-scalafix/cross-build/scala210/src/test/scala/MainTest.scala deleted file mode 100644 index d818a98d..00000000 --- a/src/sbt-test/sbt-scalafix/cross-build/scala210/src/test/scala/MainTest.scala +++ /dev/null @@ -1,7 +0,0 @@ -object MainTest { - def foo(a: (Int, String)) = a - foo(1, "str") - def main(args: Array[String]) { - println(1) - } -} diff --git a/src/sbt-test/sbt-scalafix/cross-build/scala211/src/main/scala/Main.scala b/src/sbt-test/sbt-scalafix/cross-build/scala211/src/main/scala/Main.scala deleted file mode 100644 index 4abc907d..00000000 --- a/src/sbt-test/sbt-scalafix/cross-build/scala211/src/main/scala/Main.scala +++ /dev/null @@ -1,7 +0,0 @@ -object Main { - def foo(a: (Int, String)) = a - foo(1, "str") - def main(args: Array[String]) { - println(1) - } -} diff --git a/src/sbt-test/sbt-scalafix/cross-build/scala211/src/test/scala/MainTest.scala b/src/sbt-test/sbt-scalafix/cross-build/scala211/src/test/scala/MainTest.scala deleted file mode 100644 index d818a98d..00000000 --- a/src/sbt-test/sbt-scalafix/cross-build/scala211/src/test/scala/MainTest.scala +++ /dev/null @@ -1,7 +0,0 @@ -object MainTest { - def foo(a: (Int, String)) = a - foo(1, "str") - def main(args: Array[String]) { - println(1) - } -} diff --git a/src/sbt-test/sbt-scalafix/cross-build/test b/src/sbt-test/sbt-scalafix/cross-build/test index 67ee9790..3e4b8c04 100644 --- a/src/sbt-test/sbt-scalafix/cross-build/test +++ b/src/sbt-test/sbt-scalafix/cross-build/test @@ -22,10 +22,7 @@ > it:scalafix --test ProcedureSyntax > javaProject/compile:scalafix ProcedureSyntax -# Should fail because 2.10 has no semanticdb -# Other >2.10 projects should succeed --> compile:scalafix --> test:scalafix + # it config exists only for 2.12 > it:scalafix diff --git a/src/sbt-test/sbt-scalafix/scalafixEnable/build.sbt b/src/sbt-test/sbt-scalafix/scalafixEnable/build.sbt index 3956f94f..6cf892ac 100644 --- a/src/sbt-test/sbt-scalafix/scalafixEnable/build.sbt +++ b/src/sbt-test/sbt-scalafix/scalafixEnable/build.sbt @@ -1,75 +1,77 @@ val V = _root_.scalafix.sbt.BuildInfo -// 2.10 is not supported -lazy val scala210 = project.settings( - scalaVersion := "2.10.4", - libraryDependencies := Nil, - scalacOptions := Nil +lazy val config = project + +lazy val unsupported = project.settings( + // 2.11.x is not supported + scalaVersion := "2.11.12" ) -// 2.11.x is supported -lazy val scala211_old = project.settings( - // semanticdb-scalac_2.11.0 was never available - scalaVersion := "2.11.0" +lazy val bumpScala = project.settings( + // semanticdb-scalac_2.12.0 was never available + scalaVersion := "2.12.0" ) -// 2.11.x is supported -lazy val scala211 = project.settings( - // semanticdb-scalac_2.11.11 no longer available after 4.1.9 - scalaVersion := "2.11.11" +lazy val downgradeScalameta = project.settings( + // semanticdb-scalac_2.12.4 no longer available after 4.1.9 + scalaVersion := "2.12.4" ) -// 2.12.x is supported -lazy val scala212 = project.settings( +lazy val upgradeScalameta = project.settings( // semanticdb-scalac_2.12.15 not yet available in 4.4.10, became available as of 4.4.28 scalaVersion := "2.12.15" ) -// 2.13.x is supported -lazy val scala213 = project.settings( - // semanticdb-scalac_2.13.4 available in 4.4.10, became available as of 4.4.0 +lazy val available = project.settings( + // semanticdb-scalac_2.13.4 available in 4.4.10 scalaVersion := "2.13.4", crossScalaVersions := Seq("2.12.15") ) TaskKey[Unit]("check") := { - assert((scala210 / semanticdbEnabled).value == false) - assert((scala210 / scalaVersion).value == "2.10.4") - assert((scala210 / Compile / compile / scalacOptions).value.isEmpty) + assert((unsupported / semanticdbEnabled).value == false) + assert((unsupported / scalaVersion).value == "2.11.12") + assert((unsupported / Compile / compile / scalacOptions).value.isEmpty) - assert((scala211_old / semanticdbEnabled).value == true) - assert((scala211_old / scalaVersion).value == "2.11.12") - assert((scala211_old / semanticdbCompilerPlugin).value.revision == "4.4.10") + assert((bumpScala / semanticdbEnabled).value == true) + assert((bumpScala / scalaVersion).value == V.scala212) + assert( + (bumpScala / semanticdbCompilerPlugin).value.revision == V.scalametaVersion + ) assert( - (scala211_old / Compile / compile / scalacOptions).value + (bumpScala / Compile / compile / scalacOptions).value .count(_ == "-Yrangepos") == 1 ) - assert((scala211 / semanticdbEnabled).value == true) - assert((scala211 / scalaVersion).value == "2.11.11") - assert((scala211 / semanticdbCompilerPlugin).value.revision == "4.1.9") + assert((downgradeScalameta / semanticdbEnabled).value == true) + assert((downgradeScalameta / scalaVersion).value == "2.12.4") assert( - (scala211 / Compile / compile / scalacOptions).value + (downgradeScalameta / semanticdbCompilerPlugin).value.revision == "4.1.9" + ) + assert( + (downgradeScalameta / Compile / compile / scalacOptions).value .count(_ == "-Yrangepos") == 1 ) - assert((scala212 / semanticdbEnabled).value == true) - assert((scala212 / scalaVersion).value == "2.12.15") - assert((scala212 / semanticdbCompilerPlugin).value.revision == "4.4.28") + assert((upgradeScalameta / semanticdbEnabled).value == true) + assert((upgradeScalameta / scalaVersion).value == "2.12.15") + assert( + (upgradeScalameta / semanticdbCompilerPlugin).value.revision == "4.4.28" + ) assert( - (scala212 / Compile / compile / scalacOptions).value + (upgradeScalameta / Compile / compile / scalacOptions).value .count(_ == "-Yrangepos") == 1 ) - assert((scala213 / semanticdbEnabled).value == true) - assert((scala213 / scalaVersion).value == "2.13.4") - assert((scala213 / semanticdbCompilerPlugin).value.revision == "4.4.10") + assert((available / semanticdbEnabled).value == true) + assert((available / scalaVersion).value == "2.13.4") + assert((available / semanticdbCompilerPlugin).value.revision == "4.4.10") assert( - (scala213 / Test / compile / scalacOptions).value + (available / Test / compile / scalacOptions).value .count(_ == "-Yrangepos") == 1 ) } TaskKey[Unit]("checkVersion") := { - assert((scala213 / scalaVersion).value == "2.12.15") + assert((available / scalaVersion).value == "2.12.15") } diff --git a/src/sbt-test/sbt-scalafix/scalafixEnable/scala212/src/test/scala/UnusedImports.scala b/src/sbt-test/sbt-scalafix/scalafixEnable/config/src/test/scala/UnusedImports.scala similarity index 100% rename from src/sbt-test/sbt-scalafix/scalafixEnable/scala212/src/test/scala/UnusedImports.scala rename to src/sbt-test/sbt-scalafix/scalafixEnable/config/src/test/scala/UnusedImports.scala diff --git a/src/sbt-test/sbt-scalafix/scalafixEnable/test b/src/sbt-test/sbt-scalafix/scalafixEnable/test index 2655d61c..c43cb601 100644 --- a/src/sbt-test/sbt-scalafix/scalafixEnable/test +++ b/src/sbt-test/sbt-scalafix/scalafixEnable/test @@ -2,9 +2,9 @@ > scalafixEnable > check --> scala212/test:compile -> scala212/scalafixAll RemoveUnused -> scala212/test:compile +-> config/test:compile +> config/scalafixAll RemoveUnused +> config/test:compile -> checkVersion > ++2.12.15 -v diff --git a/src/test/scala/scalafix/internal/sbt/ScalafixAPISuite.scala b/src/test/scala/scalafix/internal/sbt/ScalafixAPISuite.scala index 48dc142d..c53d6e35 100644 --- a/src/test/scala/scalafix/internal/sbt/ScalafixAPISuite.scala +++ b/src/test/scala/scalafix/internal/sbt/ScalafixAPISuite.scala @@ -16,8 +16,13 @@ class ScalafixAPISuite extends AnyFunSuite { def assertNoDiff(obtained: String, expected: String)(implicit pos: Position ): Unit = { + def removeSnapshotInfo(s: String) = + s.replaceAllLiterally( + "[info] Using SNAPSHOT artifacts for Scalafix and/or external rules, binary compatibility checks disabled", + "" + ) def strip(s: String) = s.trim.replaceAll("\r\n", "\n") - val obtainedStrip = strip(obtained) + val obtainedStrip = strip(removeSnapshotInfo(obtained)) val expectedStrip = strip(expected) assert(obtainedStrip == expectedStrip) }