diff --git a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala index 1f4cb6d0..1242584a 100644 --- a/src/main/scala/scalafix/sbt/ScalafixPlugin.scala +++ b/src/main/scala/scalafix/sbt/ScalafixPlugin.scala @@ -9,13 +9,13 @@ import sbt.* import sbt.internal.sbtscalafix.JLineAccess import sbt.internal.util.complete.Parser import sbt.plugins.JvmPlugin +import sbt.librarymanagement.ResolveException import scalafix.interfaces.{ScalafixError, ScalafixMainCallback} import scalafix.internal.sbt.* +import scala.annotation.nowarn import scala.collection.JavaConverters.collectionAsScalaIterableConverter import scala.util.control.NoStackTrace -import sbt.librarymanagement.ResolveException - import scala.util.Try object ScalafixPlugin extends AutoPlugin { @@ -64,10 +64,15 @@ object ScalafixPlugin extends AutoPlugin { "Optional list of artifacts to resolve to run custom rules. " + "Can be set in ThisBuild or at project-level." ) + @deprecated( + "scalafixScalaBinaryVersion now follows scalaBinaryVersion by default", + "0.12.1" + ) val scalafixScalaBinaryVersion: SettingKey[String] = settingKey[String]( - "The Scala binary version used for scalafix execution. Can be set in ThisBuild or at project-level. " + - "Custom rules must be compiled against that binary version. Defaults to 2.12." + "The Scala binary version used for scalafix execution. Must be set at project-level. " + + "Custom rules must be compiled against that binary version. Defaults to 2.12 for 2.12 projects, " + + "2.13 otherwise." ) val scalafixConfig: SettingKey[Option[File]] = settingKey[Option[File]]( @@ -155,7 +160,7 @@ object ScalafixPlugin extends AutoPlugin { loadedRules = { () => val scalafixInterface = ScalafixInterface( scalafixInterfaceCache.value, - scalafixScalaBinaryVersion.value, + scalafixScalaBinaryVersion.value: @nowarn, toolClasspath = Arg.ToolClasspath( // Local rules classpath must be looked up via tasks so they can't appear in completions Nil, @@ -262,7 +267,13 @@ object ScalafixPlugin extends AutoPlugin { } }, ivyConfigurations += ScalafixConfig, - scalafixAll := scalafixAllInputTask.evaluated + scalafixAll := scalafixAllInputTask.evaluated, + (scalafixScalaBinaryVersion: @nowarn) := { + scalaBinaryVersion.value match { + case "2.12" => "2.12" + case _ => "2.13" + } + } ) override lazy val globalSettings: Seq[Def.Setting[_]] = Seq( @@ -300,7 +311,6 @@ object ScalafixPlugin extends AutoPlugin { ) } }, - scalafixScalaBinaryVersion := "2.12", scalafixJGitCompletion := new JGitCompletion(baseDirectory.value.toPath) ) @@ -433,7 +443,7 @@ object ScalafixPlugin extends AutoPlugin { shellArgs, projectDepsExternal, projectDepsInternal, - scalafixScalaBinaryVersion.value, + scalafixScalaBinaryVersion.value: @nowarn, scalafixDependencies.value, allResolvers, (ThisBuild / scalafixCallback).value, diff --git a/src/sbt-test/sbt-1.4/build-lint/build.sbt b/src/sbt-test/sbt-1.4/build-lint/build.sbt index 8639100a..4e7833be 100644 --- a/src/sbt-test/sbt-1.4/build-lint/build.sbt +++ b/src/sbt-test/sbt-1.4/build-lint/build.sbt @@ -1,6 +1,5 @@ ThisBuild / scalafixDependencies := Nil ThisBuild / scalafixResolvers := Nil -ThisBuild / scalafixScalaBinaryVersion := "2.12" scalafixCaching := false scalafixConfig := None scalafixOnCompile := false diff --git a/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-2.conf b/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-2.conf new file mode 100644 index 00000000..3a228107 --- /dev/null +++ b/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-2.conf @@ -0,0 +1,2 @@ +rules = [OrganizeImports, ExplicitResultTypes] +ExplicitResultTypes.skipSimpleDefinitions = false \ No newline at end of file diff --git a/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-3.conf b/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-3.conf new file mode 100644 index 00000000..21c30ce0 --- /dev/null +++ b/src/sbt-test/sbt-1.5/cross-build-scala3/.scalafix-3.conf @@ -0,0 +1 @@ +rules = [OrganizeImports] diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/build.sbt b/src/sbt-test/sbt-1.5/cross-build-scala3/build.sbt similarity index 62% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/build.sbt rename to src/sbt-test/sbt-1.5/cross-build-scala3/build.sbt index 29d01e99..eba0e41b 100644 --- a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/build.sbt +++ b/src/sbt-test/sbt-1.5/cross-build-scala3/build.sbt @@ -1,6 +1,6 @@ import _root_.scalafix.sbt.{BuildInfo => Versions} -val scala3Version = "3.3.0" +val scala3Version = "3.4.1" ThisBuild / semanticdbEnabled := true ThisBuild / semanticdbVersion := scalafixSemanticdb.revision @@ -13,12 +13,11 @@ lazy val root = project Versions.scala213, scala3Version ), - scalacOptions ++= (if (scalaVersion.value.startsWith("2")) - Seq("-Ywarn-unused") - else Seq()), - scalafixScalaBinaryVersion := { - if (scalaBinaryVersion.value == "3") scalafixScalaBinaryVersion.value - else scalaBinaryVersion.value + scalacOptions += { + if (scalaVersion.value.startsWith("2.12")) + "-Ywarn-unused-import" + else + "-Wunused:imports" }, scalafixConfig := { if (scalaBinaryVersion.value == "3") diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/project/build.properties b/src/sbt-test/sbt-1.5/cross-build-scala3/project/build.properties similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/project/build.properties rename to src/sbt-test/sbt-1.5/cross-build-scala3/project/build.properties diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/project/plugins.sbt b/src/sbt-test/sbt-1.5/cross-build-scala3/project/plugins.sbt similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/project/plugins.sbt rename to src/sbt-test/sbt-1.5/cross-build-scala3/project/plugins.sbt diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-2/Main.scala b/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-2/Main.scala similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-2/Main.scala rename to src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-2/Main.scala diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-2/Main.scala.expected b/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-2/Main.scala.expected similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-2/Main.scala.expected rename to src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-2/Main.scala.expected diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-3/Main.scala b/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-3/Main.scala similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-3/Main.scala rename to src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-3/Main.scala diff --git a/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-3/Main.scala.expected b/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-3/Main.scala.expected new file mode 100644 index 00000000..cb096903 --- /dev/null +++ b/src/sbt-test/sbt-1.5/cross-build-scala3/src/main/scala-3/Main.scala.expected @@ -0,0 +1,5 @@ +import scala.Int + +object Main { + def foo(a: Int) = a + 2.0f +} \ No newline at end of file diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/test b/src/sbt-test/sbt-1.5/cross-build-scala3/test similarity index 100% rename from src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/test rename to src/sbt-test/sbt-1.5/cross-build-scala3/test diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-2.conf b/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-2.conf deleted file mode 100644 index bbc1675b..00000000 --- a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-2.conf +++ /dev/null @@ -1,3 +0,0 @@ -rules = [DisableSyntax, OrganizeImports, ExplicitResultTypes] -OrganizeImports.removeUnused = true -ExplicitResultTypes.skipSimpleDefinitions = false \ No newline at end of file diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-3.conf b/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-3.conf deleted file mode 100644 index c2231433..00000000 --- a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/.scalafix-3.conf +++ /dev/null @@ -1,2 +0,0 @@ -rules = [DisableSyntax, OrganizeImports] -OrganizeImports.removeUnused = false \ No newline at end of file diff --git a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-3/Main.scala.expected b/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-3/Main.scala.expected deleted file mode 100644 index bf8fd25a..00000000 --- a/src/sbt-test/sbt-1.5/cross-build-scalafixScalaBinaryVersion/src/main/scala-3/Main.scala.expected +++ /dev/null @@ -1,7 +0,0 @@ -import scala.Int -import scala.collection.AbstractSeq -import scala.collection.Seq - -object Main { - def foo(a: Int) = a + 2.0f -} \ No newline at end of file diff --git a/src/sbt-test/sbt-scalafix/local-rules/build.sbt b/src/sbt-test/sbt-scalafix/local-rules/build.sbt index 1fef774b..03b7f94a 100644 --- a/src/sbt-test/sbt-scalafix/local-rules/build.sbt +++ b/src/sbt-test/sbt-scalafix/local-rules/build.sbt @@ -7,10 +7,7 @@ inThisBuild( "ch.epfl.scala" %% "example-scalafix-rule" % "1.4.0" ), resolvers += Resolver.sonatypeRepo("snapshots"), - scalaVersion := "2.13.11", // out of sync with scalafix.sbt.BuildInfo.scala213 on purpose - scalafixScalaBinaryVersion := - // this should be the default in sbt-scalafix 1.0 - CrossVersion.binaryScalaVersion(scalaVersion.value) + scalaVersion := "2.13.11" // out of sync with scalafix.sbt.BuildInfo.scala213 on purpose ) ) diff --git a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/build.sbt b/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/build.sbt deleted file mode 100644 index 21462e27..00000000 --- a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/build.sbt +++ /dev/null @@ -1,10 +0,0 @@ -import _root_.scalafix.sbt.{BuildInfo => V} - -inThisBuild( - List( - addCompilerPlugin(scalafixSemanticdb), - scalacOptions += "-Yrangepos", - scalaVersion := V.scala213, - scalafixScalaBinaryVersion := scalaBinaryVersion.value // this should be the default in sbt-scalafix 1.0 - ) -) diff --git a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/project/plugins.sbt b/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/project/plugins.sbt deleted file mode 100644 index 2d3b4d3b..00000000 --- a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/project/plugins.sbt +++ /dev/null @@ -1,2 +0,0 @@ -resolvers += Resolver.sonatypeRepo("public") -addSbtPlugin("ch.epfl.scala" % "sbt-scalafix" % sys.props("plugin.version")) diff --git a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/src/main/scala/NeedExplicitResultTypes.scala b/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/src/main/scala/NeedExplicitResultTypes.scala deleted file mode 100644 index 1da5a2da..00000000 --- a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/src/main/scala/NeedExplicitResultTypes.scala +++ /dev/null @@ -1,6 +0,0 @@ -object NeedExplicitResultTypes { - def a = { - println("foobar") - 123 - } -} diff --git a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/test b/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/test deleted file mode 100644 index 06f59062..00000000 --- a/src/sbt-test/sbt-scalafix/scalafixScalaBinaryVersion/test +++ /dev/null @@ -1,5 +0,0 @@ -# ExplicitResultTypes uses the presentation compiler so the rule must run with the same scala binary version as the target --> scalafix --check ExplicitResultTypes -> scalafix ExplicitResultTypes -> scalafix --check ExplicitResultTypes -