diff --git a/build.sc b/build.sc index 14d3eb3..2f4bf28 100644 --- a/build.sc +++ b/build.sc @@ -58,6 +58,14 @@ trait ITestCross extends MillIntegrationTestModule with Cross.Module[String] { TestInvocation.Targets(Seq("__.fix")), TestInvocation.Targets(Seq("verify")) ), + PathRef(sources().head.path / "fix-2.12") -> Seq( + TestInvocation.Targets(Seq("__.fix")), + TestInvocation.Targets(Seq("verify")) + ), + PathRef(sources().head.path / "fix-3.5") -> Seq( + TestInvocation.Targets(Seq("__.fix")), + TestInvocation.Targets(Seq("verify")) + ), PathRef(sources().head.path / "check") -> Seq( TestInvocation.Targets(Seq("__.fix", "--check")) ), diff --git a/itest/src/custom-rule/build.sc b/itest/src/custom-rule/build.sc index e1184d3..dd94346 100644 --- a/itest/src/custom-rule/build.sc +++ b/itest/src/custom-rule/build.sc @@ -5,9 +5,9 @@ import mill.scalalib._ import os._ object project extends ScalaModule with ScalafixModule { - def scalaVersion = "2.13.12" + def scalaVersion = "2.12.17" def semanticDbEnablePluginScalacOptions = super.semanticDbEnablePluginScalacOptions() ++ Seq("-P:semanticdb:synthetics:on") - def scalafixIvyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-migrations:2.11.0") + def scalafixIvyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-migrations:2.12.0") } def verify() = diff --git a/itest/src/fix-2.12/build.sc b/itest/src/fix-2.12/build.sc index 3b6f862..21dd5f5 100644 --- a/itest/src/fix-2.12/build.sc +++ b/itest/src/fix-2.12/build.sc @@ -7,12 +7,15 @@ import os._ object project extends ScalaModule with ScalafixModule { def scalaVersion = "2.12.17" def scalacOptions = Seq("-Ywarn-unused") + def ivyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-compat:2.12.0") } def verify() = T.command { val fixedScala = read(pwd / "project" / "src" / "Fix.scala") - val expected = """object Fix { + val expected = """ + | + |object Fix { | def procedure(): Unit = {} |} |""".stripMargin diff --git a/itest/src/fix-3.5/.scalafix.conf b/itest/src/fix-3.5/.scalafix.conf new file mode 100644 index 0000000..afaacc9 --- /dev/null +++ b/itest/src/fix-3.5/.scalafix.conf @@ -0,0 +1,3 @@ +rules = [ + ExplicitResultTypes +] diff --git a/itest/src/fix-3.5/build.sc b/itest/src/fix-3.5/build.sc new file mode 100644 index 0000000..1902c8e --- /dev/null +++ b/itest/src/fix-3.5/build.sc @@ -0,0 +1,21 @@ +import $file.plugins +import com.goyeau.mill.scalafix.ScalafixModule +import mill._ +import mill.scalalib._ +import os._ + +object project extends ScalaModule with ScalafixModule { + def scalaVersion = "3.5.1" +} + +def verify() = + T.command { + val fixedScala = read(pwd / "project" / "src" / "Fix.scala") + val expected = """object Fix { + | // use a 3.5.x-only feature to fail if a Scala 3 LTS compiler is used + | // https://www.scala-lang.org/blog/2024/08/22/scala-3.5.0-released.html#support-for-binary-integer-literals + | def myComplexMethod: Map[Int, String] = 1.to(0B1010).map(i => i -> i.toString).toMap + |} + |""".stripMargin + assert(fixedScala == expected) + } diff --git a/itest/src/fix-3.5/project/src/Fix.scala b/itest/src/fix-3.5/project/src/Fix.scala new file mode 100644 index 0000000..015479f --- /dev/null +++ b/itest/src/fix-3.5/project/src/Fix.scala @@ -0,0 +1,5 @@ +object Fix { + // use a 3.5.x-only feature to fail if a Scala 3 LTS compiler is used + // https://www.scala-lang.org/blog/2024/08/22/scala-3.5.0-released.html#support-for-binary-integer-literals + def myComplexMethod = 1.to(0B1010).map(i => i -> i.toString).toMap +} diff --git a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala index 56e4f56..c55eefe 100644 --- a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala +++ b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala @@ -9,12 +9,14 @@ import mill.define.Command import scalafix.interfaces.Scalafix import scalafix.interfaces.ScalafixError.* + import scala.compat.java8.OptionConverters.* import scala.jdk.CollectionConverters.* trait ScalafixModule extends ScalaModule { - def scalafixConfig: T[Option[os.Path]] = T(None) - def scalafixIvyDeps: T[Agg[Dep]] = Agg.empty[Dep] + def scalafixConfig: T[Option[os.Path]] = T(None) + def scalafixIvyDeps: T[Agg[Dep]] = Agg.empty[Dep] + @deprecated("Scalafix now follows scalaVersion", since = "0.4.2") def scalafixScalaBinaryVersion: T[String] = "2.12" /** Run Scalafix. @@ -27,7 +29,6 @@ trait ScalafixModule extends ScalaModule { filesToFix(sources()).map(_.path), classpath = (compileClasspath() ++ localClasspath() ++ Seq(semanticDbData())).iterator.toSeq.map(_.path), scalaVersion(), - scalafixScalaBinaryVersion(), scalacOptions(), scalafixIvyDeps(), scalafixConfig(), @@ -38,6 +39,7 @@ trait ScalafixModule extends ScalaModule { } object ScalafixModule { + @deprecated("Use overload without scalaBinaryVersion and with wd instead", since = "0.4.2") def fixAction( log: Logger, repositories: Seq[Repository], @@ -55,7 +57,6 @@ object ScalafixModule { sources, classpath, scalaVersion, - scalaBinaryVersion, scalacOptions, scalafixIvyDeps, scalafixConfig, @@ -69,7 +70,6 @@ object ScalafixModule { sources: Seq[os.Path], classpath: Seq[os.Path], scalaVersion: String, - scalaBinaryVersion: String, scalacOptions: Seq[String], scalafixIvyDeps: Agg[Dep], scalafixConfig: Option[os.Path], @@ -78,7 +78,7 @@ object ScalafixModule { ): Result[Unit] = if (sources.nonEmpty) { val scalafix = Scalafix - .fetchAndClassloadInstance(scalaBinaryVersion, repositories.map(CoursierUtils.toApiRepository).asJava) + .fetchAndClassloadInstance(scalaVersion, repositories.map(CoursierUtils.toApiRepository).asJava) .newArguments() .withParsedArguments(args.asJava) .withWorkingDirectory(wd.toNIO) @@ -124,4 +124,30 @@ object ScalafixModule { if (os.isDir(pathRef.path)) os.walk(pathRef.path).filter(file => os.isFile(file) && (file.ext == "scala")) else Seq(pathRef.path) } yield PathRef(file) + + @deprecated("Use overload without scalaBinaryVersion instead", since = "0.4.2") + def fixAction( + log: Logger, + repositories: Seq[Repository], + sources: Seq[os.Path], + classpath: Seq[os.Path], + scalaVersion: String, + scalaBinaryVersion: String, + scalacOptions: Seq[String], + scalafixIvyDeps: Agg[Dep], + scalafixConfig: Option[os.Path], + args: Seq[String], + wd: os.Path + ): Result[Unit] = fixAction( + log, + repositories, + sources, + classpath, + scalaVersion, + scalacOptions, + scalafixIvyDeps, + scalafixConfig, + args, + wd + ) }