From 1ad23524ed2e9a6b31dc91d6b681e858ce505580 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Dec 2023 22:57:29 -0800 Subject: [PATCH 1/8] . --- .github/workflows/actions.yml | 2 +- .scalafix.conf | 3 +++ build.sc | 12 ++++++++++-- 3 files changed, 14 insertions(+), 3 deletions(-) create mode 100644 .scalafix.conf diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 501bee8d319..43656cc9f35 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -95,7 +95,7 @@ jobs: uses: ./.github/workflows/run-mill-action.yml with: java-version: '8' - millargs: mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources + millargs: -i __.fix && git diff --exit-code bincompat-check: uses: ./.github/workflows/run-mill-action.yml diff --git a/.scalafix.conf b/.scalafix.conf new file mode 100644 index 00000000000..1df6ecc1e79 --- /dev/null +++ b/.scalafix.conf @@ -0,0 +1,3 @@ +rules = [ + RemoveUnused +] \ No newline at end of file diff --git a/build.sc b/build.sc index ab79d0d7706..82183e881d5 100644 --- a/build.sc +++ b/build.sc @@ -7,11 +7,13 @@ import $ivy.`de.tototec::de.tobiasroeser.mill.vcs.version::0.4.0` import $ivy.`com.github.lolgab::mill-mima::0.1.0` import $ivy.`net.sourceforge.htmlcleaner:htmlcleaner:2.29` import $ivy.`com.lihaoyi::mill-contrib-buildinfo:` +import $ivy.`com.goyeau::mill-scalafix::0.3.1` // imports import com.github.lolgab.mill.mima.{CheckDirection, ProblemFilter, Mima} import coursier.maven.MavenRepository import de.tobiasroeser.mill.vcs.version.VcsVersion +import com.goyeau.mill.scalafix.ScalafixModule import mill._ import mill.api.JarManifest import mill.define.NamedTask @@ -317,10 +319,10 @@ trait MillPublishJavaModule extends MillJavaModule with PublishModule { /** * Some custom scala settings and test convenience */ -trait MillScalaModule extends ScalaModule with MillJavaModule { outer => +trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModule{ outer => def scalaVersion = Deps.scalaVersion def scalacOptions = - super.scalacOptions() ++ Seq("-deprecation", "-P:acyclic:force", "-feature", "-Xlint:unused") + super.scalacOptions() ++ Seq("-deprecation", "-P:acyclic:force", "-feature", "-Ywarn-unused:imports") def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest) def testModuleDeps: Seq[JavaModule] = @@ -820,6 +822,8 @@ object contrib extends Module { // Worker for Scoverage 1.x object worker extends MillPublishScalaModule { + // scoverage is on an old Scala version which doesnt support scalafix + def fix(args: String*): Command[Unit] = T.command{} def compileModuleDeps = Seq(main.api) def moduleDeps = Seq(scoverage.api) def testDepPaths = T { Seq(compile().classes) } @@ -1044,6 +1048,8 @@ object example extends MillScalaModule { object web extends Cross[ExampleCrossModule](listIn(millSourcePath / "web")) trait ExampleCrossModule extends IntegrationTestCrossModule { + // disable scalafix because these example modules don't have sources causing it to misbehave + def fix(args: String*): Command[Unit] = T.command{} def testRepoRoot: T[PathRef] = T.source(millSourcePath) def compile = example.compile() def forkEnv = super.forkEnv() ++ Map("MILL_EXAMPLE_PARSED" -> upickle.default.write(parsed())) @@ -1301,6 +1307,8 @@ object dist extends MillPublishJavaModule { } object dev extends MillPublishScalaModule { + // disable scalafix here because it crashes when a module has no sources + def fix(args: String*): Command[Unit] = T.command{} def moduleDeps = Seq(runner, idea) def testTransitiveDeps = super.testTransitiveDeps() ++ Seq( From 491dd326d858fe07b35fa9f1cae8a4108760105e Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 08:36:55 +0800 Subject: [PATCH 2/8] . --- .github/workflows/actions.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index 43656cc9f35..ce1aac3ae14 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -92,6 +92,12 @@ jobs: millargs: ${{ matrix.millargs }} format-check: + uses: ./.github/workflows/run-mill-action.yml + with: + java-version: '8' + millargs: mill.scalalib.scalafmt.ScalafmtModule/checkFormatAll __.sources + + scalafix-check: uses: ./.github/workflows/run-mill-action.yml with: java-version: '8' From 2c11a6aa0c275b71a585dba2516de06d0da2a751 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 08:38:28 +0800 Subject: [PATCH 3/8] . --- build.sc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/build.sc b/build.sc index 82183e881d5..397dbca33f7 100644 --- a/build.sc +++ b/build.sc @@ -322,7 +322,7 @@ trait MillPublishJavaModule extends MillJavaModule with PublishModule { trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModule{ outer => def scalaVersion = Deps.scalaVersion def scalacOptions = - super.scalacOptions() ++ Seq("-deprecation", "-P:acyclic:force", "-feature", "-Ywarn-unused:imports") + super.scalacOptions() ++ Seq("-deprecation", "-P:acyclic:force", "-feature", "-Xlint:unused") def testIvyDeps: T[Agg[Dep]] = Agg(Deps.utest) def testModuleDeps: Seq[JavaModule] = From 51efa98e6d262951fc4ee23998cf7ccb49f0b96c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 08:44:43 +0800 Subject: [PATCH 4/8] . --- .../src/mill/contrib/scoverage/ScoverageReportWorker.scala | 2 +- contrib/twirllib/src/mill/twirllib/TwirlWorker.scala | 2 +- idea/src/mill/idea/GenIdeaImpl.scala | 5 +---- .../private-methods/test/src/PrivateMethodsTests.scala | 2 +- main/define/src/mill/define/EnclosingClass.scala | 1 - main/eval/src/mill/eval/EvaluatorCore.scala | 2 +- main/eval/src/mill/eval/GroupEvaluator.scala | 2 +- scalalib/src/mill/scalalib/Dep.scala | 4 ++-- scalalib/src/mill/scalalib/GenIdeaImpl.scala | 2 +- 9 files changed, 9 insertions(+), 13 deletions(-) diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala index e0ab30f7bdc..fb3b37872c9 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala @@ -9,7 +9,7 @@ class ScoverageReportWorker extends AutoCloseable { private[this] var scoverageClCache = Option.empty[(Long, ClassLoader)] def bridge(classpath: Agg[PathRef])(implicit ctx: Ctx): ScoverageReportWorkerApi = { - val klassName = "mill.contrib.scoverage.worker.ScoverageReportWorkerImpl" + val classloaderSig = classpath.hashCode val cl = scoverageClCache match { case Some((sig, cl)) if sig == classloaderSig => cl diff --git a/contrib/twirllib/src/mill/twirllib/TwirlWorker.scala b/contrib/twirllib/src/mill/twirllib/TwirlWorker.scala index bbd4ea79775..c9ba5888879 100644 --- a/contrib/twirllib/src/mill/twirllib/TwirlWorker.scala +++ b/contrib/twirllib/src/mill/twirllib/TwirlWorker.scala @@ -103,7 +103,7 @@ class TwirlWorker { // Codec codec, // boolean inclusiveDot // ) - val o = compileMethod.invoke( + compileMethod.invoke( null, source, sourceDirectory, diff --git a/idea/src/mill/idea/GenIdeaImpl.scala b/idea/src/mill/idea/GenIdeaImpl.scala index 0c5a8cec131..14d6094d123 100755 --- a/idea/src/mill/idea/GenIdeaImpl.scala +++ b/idea/src/mill/idea/GenIdeaImpl.scala @@ -205,7 +205,7 @@ case class GenIdeaImpl( extRunIvyDeps().map(_.path).map(Scoped(_, Some("RUNTIME"))) // unused, but we want to trigger sources, to have them available (automatically) // TODO: make this a separate eval to handle resolve errors - val resolvedSrcs: Agg[PathRef] = externalSources() + externalSources() val resolvedSp: Agg[PathRef] = scalacPluginDependencies() val resolvedCompilerCp: Agg[PathRef] = scalaCompilerClasspath() @@ -444,9 +444,6 @@ case class GenIdeaImpl( r + (key -> (r.getOrElse(key, Vector()) :+ q.module)) } - val allBuildLibraries: Set[ResolvedLibrary] = - resolvedLibraries(buildLibraryPaths ++ buildDepsPaths).toSet - val fixedFiles: Seq[(SubPath, Elem)] = Seq( Tuple2(os.sub / "misc.xml", miscXmlTemplate(jdkInfo)), Tuple2(os.sub / "scala_settings.xml", scalaSettingsTemplate()), diff --git a/integration/feature/private-methods/test/src/PrivateMethodsTests.scala b/integration/feature/private-methods/test/src/PrivateMethodsTests.scala index 15a2a90e59a..c051daeea38 100644 --- a/integration/feature/private-methods/test/src/PrivateMethodsTests.scala +++ b/integration/feature/private-methods/test/src/PrivateMethodsTests.scala @@ -4,7 +4,7 @@ import utest._ object PrivateMethodsTests extends IntegrationTestSuite { val tests = Tests { - val wsRoot = initWorkspace() + initWorkspace() "simple" - { // Simple public target depending on private target works val pub = evalStdout("show", "pub") diff --git a/main/define/src/mill/define/EnclosingClass.scala b/main/define/src/mill/define/EnclosingClass.scala index 62f950164fc..26e8ec0d25d 100644 --- a/main/define/src/mill/define/EnclosingClass.scala +++ b/main/define/src/mill/define/EnclosingClass.scala @@ -8,7 +8,6 @@ object EnclosingClass { implicit def generate: EnclosingClass = macro impl def impl(c: Context): c.Tree = { import c.universe._ - val cls = c.internal.enclosingOwner.owner.asType.asClass // q"new _root_.mill.define.EnclosingClass(classOf[$cls])" q"new _root_.mill.define.EnclosingClass(this.getClass)" } diff --git a/main/eval/src/mill/eval/EvaluatorCore.scala b/main/eval/src/mill/eval/EvaluatorCore.scala index 8704e6702e3..80f37c20864 100644 --- a/main/eval/src/mill/eval/EvaluatorCore.scala +++ b/main/eval/src/mill/eval/EvaluatorCore.scala @@ -2,7 +2,7 @@ package mill.eval import mill.api.Result.{Aborted, Failing} import mill.api.Strict.Agg -import mill.api.{Ctx, _} +import mill.api._ import mill.define._ import mill.eval.Evaluator.TaskResult import mill.util._ diff --git a/main/eval/src/mill/eval/GroupEvaluator.scala b/main/eval/src/mill/eval/GroupEvaluator.scala index a0f2e133b42..faef3527561 100644 --- a/main/eval/src/mill/eval/GroupEvaluator.scala +++ b/main/eval/src/mill/eval/GroupEvaluator.scala @@ -9,7 +9,7 @@ import mill.util._ import java.io.PrintStream import scala.collection.mutable -import scala.reflect.NameTransformer.{encode, decode} +import scala.reflect.NameTransformer.encode import scala.util.DynamicVariable import scala.util.control.NonFatal diff --git a/scalalib/src/mill/scalalib/Dep.scala b/scalalib/src/mill/scalalib/Dep.scala index cf1c1665a86..dd1c6f1321c 100644 --- a/scalalib/src/mill/scalalib/Dep.scala +++ b/scalalib/src/mill/scalalib/Dep.scala @@ -136,7 +136,7 @@ object Dep { force ) } - private implicit val depFormat: RW[Dependency] = mill.scalalib.JsonFormatters.depFormat + implicit def rw: RW[Dep] = macroRW } @@ -208,6 +208,6 @@ case class BoundDep( } object BoundDep { - private implicit val depFormat: RW[Dependency] = mill.scalalib.JsonFormatters.depFormat + mill.scalalib.JsonFormatters.depFormat implicit val jsonify: upickle.default.ReadWriter[BoundDep] = upickle.default.macroRW } diff --git a/scalalib/src/mill/scalalib/GenIdeaImpl.scala b/scalalib/src/mill/scalalib/GenIdeaImpl.scala index 61599825bcb..74ab3a847a4 100755 --- a/scalalib/src/mill/scalalib/GenIdeaImpl.scala +++ b/scalalib/src/mill/scalalib/GenIdeaImpl.scala @@ -178,7 +178,7 @@ case class GenIdeaImpl( extRunIvyDeps().map(_.path).map(Scoped(_, Some("RUNTIME"))) // unused, but we want to trigger sources, to have them available (automatically) // TODO: make this a separate eval to handle resolve errors - val resolvedSrcs: Agg[PathRef] = externalSources() + externalSources() val resolvedSp: Agg[PathRef] = scalacPluginDependencies() val resolvedCompilerCp: Agg[PathRef] = scalaCompilerClasspath() From 157b18c1f9afff58a5df6cc126e6592c050e0985 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 08:48:20 +0800 Subject: [PATCH 5/8] . --- scalalib/src/mill/scalalib/Dep.scala | 1 - 1 file changed, 1 deletion(-) diff --git a/scalalib/src/mill/scalalib/Dep.scala b/scalalib/src/mill/scalalib/Dep.scala index dd1c6f1321c..dfd4063b135 100644 --- a/scalalib/src/mill/scalalib/Dep.scala +++ b/scalalib/src/mill/scalalib/Dep.scala @@ -208,6 +208,5 @@ case class BoundDep( } object BoundDep { - mill.scalalib.JsonFormatters.depFormat implicit val jsonify: upickle.default.ReadWriter[BoundDep] = upickle.default.macroRW } From b0e1966b9172fd342a847c643902c5bebb8f0a03 Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 09:36:12 +0800 Subject: [PATCH 6/8] . --- scalalib/src/mill/scalalib/Dep.scala | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/scalalib/src/mill/scalalib/Dep.scala b/scalalib/src/mill/scalalib/Dep.scala index dfd4063b135..ca00a2365ba 100644 --- a/scalalib/src/mill/scalalib/Dep.scala +++ b/scalalib/src/mill/scalalib/Dep.scala @@ -5,6 +5,8 @@ import mill.scalalib.CrossVersion._ import coursier.core.Dependency import mill.scalalib.api.ZincWorkerUtil +import scala.annotation.unused + case class Dep(dep: coursier.Dependency, cross: CrossVersion, force: Boolean) { require( !dep.module.name.value.contains("/") && @@ -136,7 +138,7 @@ object Dep { force ) } - + @unused private implicit val depFormat: RW[Dependency] = mill.scalalib.JsonFormatters.depFormat implicit def rw: RW[Dep] = macroRW } @@ -208,5 +210,6 @@ case class BoundDep( } object BoundDep { + @unused private implicit val depFormat: RW[Dependency] = mill.scalalib.JsonFormatters.depFormat implicit val jsonify: upickle.default.ReadWriter[BoundDep] = upickle.default.macroRW } From c1face8b6f35c141e2b2a0224a3d5355cff82b5c Mon Sep 17 00:00:00 2001 From: Your Name Date: Tue, 12 Dec 2023 12:33:43 +0800 Subject: [PATCH 7/8] . --- .../src/mill/contrib/scoverage/ScoverageReportWorker.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala index fb3b37872c9..c0e7f22ac69 100644 --- a/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala +++ b/contrib/scoverage/src/mill/contrib/scoverage/ScoverageReportWorker.scala @@ -9,7 +9,7 @@ class ScoverageReportWorker extends AutoCloseable { private[this] var scoverageClCache = Option.empty[(Long, ClassLoader)] def bridge(classpath: Agg[PathRef])(implicit ctx: Ctx): ScoverageReportWorkerApi = { - + val classloaderSig = classpath.hashCode val cl = scoverageClCache match { case Some((sig, cl)) if sig == classloaderSig => cl From 6ed8919ec7ae068d97be401ce1538079a6dc60db Mon Sep 17 00:00:00 2001 From: Tobias Roeser Date: Tue, 12 Dec 2023 22:08:28 +0100 Subject: [PATCH 8/8] Use `fix --check` in CI --- .github/workflows/actions.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/actions.yml b/.github/workflows/actions.yml index ce1aac3ae14..f669f604e12 100644 --- a/.github/workflows/actions.yml +++ b/.github/workflows/actions.yml @@ -101,7 +101,7 @@ jobs: uses: ./.github/workflows/run-mill-action.yml with: java-version: '8' - millargs: -i __.fix && git diff --exit-code + millargs: -i -k __.fix --check bincompat-check: uses: ./.github/workflows/run-mill-action.yml