From afd488d38a34f11e0f494338a2c3b2930214baee Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 12:37:44 +0200 Subject: [PATCH 1/8] Pass scalaVersion to Scalafix as needed for Scalafix 0.13.0 --- build.sc | 8 ++++++++ itest/src/fix-3.5/.scalafix.conf | 3 +++ itest/src/fix-3.5/build.sc | 20 +++++++++++++++++++ itest/src/fix-3.5/project/src/Fix.scala | 3 +++ .../goyeau/mill/scalafix/ScalafixModule.scala | 12 +++++++---- 5 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 itest/src/fix-3.5/.scalafix.conf create mode 100644 itest/src/fix-3.5/build.sc create mode 100644 itest/src/fix-3.5/project/src/Fix.scala 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/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..bece231 --- /dev/null +++ b/itest/src/fix-3.5/build.sc @@ -0,0 +1,20 @@ +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 { + | def myComplexMethod: Map[Int, String] = 1.to(10).map(i => i -> i.toString).toMap + |} + |""".stripMargin + println(fixedScala) + 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..c2526fb --- /dev/null +++ b/itest/src/fix-3.5/project/src/Fix.scala @@ -0,0 +1,3 @@ +object Fix { + def myComplexMethod = 1.to(10).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..8fae4ae 100644 --- a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala +++ b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala @@ -9,12 +9,15 @@ import mill.define.Command import scalafix.interfaces.Scalafix import scalafix.interfaces.ScalafixError.* + +import scala.annotation.nowarn 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 +30,7 @@ trait ScalafixModule extends ScalaModule { filesToFix(sources()).map(_.path), classpath = (compileClasspath() ++ localClasspath() ++ Seq(semanticDbData())).iterator.toSeq.map(_.path), scalaVersion(), - scalafixScalaBinaryVersion(), + scalafixScalaBinaryVersion(): @nowarn("cat=deprecation"), scalacOptions(), scalafixIvyDeps(), scalafixConfig(), @@ -63,6 +66,7 @@ object ScalafixModule { os.pwd ) + @nowarn("msg=parameter scalaBinaryVersion in method fixAction is never used") def fixAction( log: Logger, repositories: Seq[Repository], @@ -78,7 +82,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) From 29a274ca6b261fe3a38a83a45faaf2a76ad629f3 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 13:06:13 +0200 Subject: [PATCH 2/8] Fix fix-2.12 test --- itest/src/fix-2.12/build.sc | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/itest/src/fix-2.12/build.sc b/itest/src/fix-2.12/build.sc index 3b6f862..e97c8af 100644 --- a/itest/src/fix-2.12/build.sc +++ b/itest/src/fix-2.12/build.sc @@ -5,14 +5,17 @@ import mill.scalalib._ import os._ object project extends ScalaModule with ScalafixModule { - def scalaVersion = "2.12.17" + def scalaVersion = "2.12.19" 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 From 8b31cd45e244f75184c29bb3b84dda1121c76557 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 13:07:19 +0200 Subject: [PATCH 3/8] Use Scala 3.5 specific feature in test Co-authored-by: Brice Jaglin --- itest/src/fix-3.5/project/src/Fix.scala | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/itest/src/fix-3.5/project/src/Fix.scala b/itest/src/fix-3.5/project/src/Fix.scala index c2526fb..015479f 100644 --- a/itest/src/fix-3.5/project/src/Fix.scala +++ b/itest/src/fix-3.5/project/src/Fix.scala @@ -1,3 +1,5 @@ object Fix { - def myComplexMethod = 1.to(10).map(i => i -> i.toString).toMap + // 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 } From ad4b5943938f3ad59bbaedce978ca67a15da55d0 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 13:08:12 +0200 Subject: [PATCH 4/8] Remove debug print Co-authored-by: Brice Jaglin --- itest/src/fix-3.5/build.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/itest/src/fix-3.5/build.sc b/itest/src/fix-3.5/build.sc index bece231..8bf31cd 100644 --- a/itest/src/fix-3.5/build.sc +++ b/itest/src/fix-3.5/build.sc @@ -15,6 +15,5 @@ def verify() = | def myComplexMethod: Map[Int, String] = 1.to(10).map(i => i -> i.toString).toMap |} |""".stripMargin - println(fixedScala) assert(fixedScala == expected) } From 1df01e02204bdb91d2d1a99e7011084e21134094 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 13:15:06 +0200 Subject: [PATCH 5/8] Add deprecated overload instead of using `@nowarn` --- .../goyeau/mill/scalafix/ScalafixModule.scala | 32 ++++++++++++++++--- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala index 8fae4ae..c55eefe 100644 --- a/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala +++ b/mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala @@ -10,7 +10,6 @@ import mill.define.Command import scalafix.interfaces.Scalafix import scalafix.interfaces.ScalafixError.* -import scala.annotation.nowarn import scala.compat.java8.OptionConverters.* import scala.jdk.CollectionConverters.* @@ -30,7 +29,6 @@ trait ScalafixModule extends ScalaModule { filesToFix(sources()).map(_.path), classpath = (compileClasspath() ++ localClasspath() ++ Seq(semanticDbData())).iterator.toSeq.map(_.path), scalaVersion(), - scalafixScalaBinaryVersion(): @nowarn("cat=deprecation"), scalacOptions(), scalafixIvyDeps(), scalafixConfig(), @@ -41,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], @@ -58,7 +57,6 @@ object ScalafixModule { sources, classpath, scalaVersion, - scalaBinaryVersion, scalacOptions, scalafixIvyDeps, scalafixConfig, @@ -66,14 +64,12 @@ object ScalafixModule { os.pwd ) - @nowarn("msg=parameter scalaBinaryVersion in method fixAction is never used") 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], @@ -128,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 + ) } From 6cd080e4ff77a4ec81dd4caf3debf1669e0ddf43 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 13:30:21 +0200 Subject: [PATCH 6/8] Fix custom-rule test --- itest/src/custom-rule/build.sc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/itest/src/custom-rule/build.sc b/itest/src/custom-rule/build.sc index e1184d3..c374a55 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.19" 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() = From cb02ca136b13f40b4896fad30b2d33b89bc2cf41 Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 15:00:29 +0200 Subject: [PATCH 7/8] Fix tests --- itest/src/custom-rule/build.sc | 2 +- itest/src/fix-2.12/build.sc | 2 +- itest/src/fix-3.5/build.sc | 5 ++++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/itest/src/custom-rule/build.sc b/itest/src/custom-rule/build.sc index c374a55..dd94346 100644 --- a/itest/src/custom-rule/build.sc +++ b/itest/src/custom-rule/build.sc @@ -5,7 +5,7 @@ import mill.scalalib._ import os._ object project extends ScalaModule with ScalafixModule { - def scalaVersion = "2.12.19" + 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.12.0") } diff --git a/itest/src/fix-2.12/build.sc b/itest/src/fix-2.12/build.sc index e97c8af..21dd5f5 100644 --- a/itest/src/fix-2.12/build.sc +++ b/itest/src/fix-2.12/build.sc @@ -5,7 +5,7 @@ import mill.scalalib._ import os._ object project extends ScalaModule with ScalafixModule { - def scalaVersion = "2.12.19" + def scalaVersion = "2.12.17" def scalacOptions = Seq("-Ywarn-unused") def ivyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-compat:2.12.0") } diff --git a/itest/src/fix-3.5/build.sc b/itest/src/fix-3.5/build.sc index 8bf31cd..2860a69 100644 --- a/itest/src/fix-3.5/build.sc +++ b/itest/src/fix-3.5/build.sc @@ -12,8 +12,11 @@ def verify() = T.command { val fixedScala = read(pwd / "project" / "src" / "Fix.scala") val expected = """object Fix { - | def myComplexMethod: Map[Int, String] = 1.to(10).map(i => i -> i.toString).toMap + | // 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 + println(fixedScala) assert(fixedScala == expected) } From 2478d47de21f3fd60d907b28c7a0536844adfa4f Mon Sep 17 00:00:00 2001 From: Lorenzo Gabriele Date: Mon, 30 Sep 2024 16:16:38 +0200 Subject: [PATCH 8/8] Remove debug print --- itest/src/fix-3.5/build.sc | 1 - 1 file changed, 1 deletion(-) diff --git a/itest/src/fix-3.5/build.sc b/itest/src/fix-3.5/build.sc index 2860a69..1902c8e 100644 --- a/itest/src/fix-3.5/build.sc +++ b/itest/src/fix-3.5/build.sc @@ -17,6 +17,5 @@ def verify() = | def myComplexMethod: Map[Int, String] = 1.to(0B1010).map(i => i -> i.toString).toMap |} |""".stripMargin - println(fixedScala) assert(fixedScala == expected) }