Skip to content

Commit

Permalink
Run -rewrite -source 3.6-migration, enable Scalafix in tests (#4512)
Browse files Browse the repository at this point in the history
This wipes out the bulk of the annoying warnings that scroll past when
compiling

There are still a few residual warnings, but I'll tackle those in a
follow up
  • Loading branch information
lihaoyi authored Feb 8, 2025
1 parent 8d73650 commit be14d4e
Show file tree
Hide file tree
Showing 203 changed files with 892 additions and 926 deletions.
5 changes: 0 additions & 5 deletions .scalafix-3.conf

This file was deleted.

1 change: 0 additions & 1 deletion .scalafix.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
rules = [
RemoveUnused,
NoAutoTupling
ExplicitResultTypes
]
2 changes: 1 addition & 1 deletion bsp/src/mill/bsp/BspWorker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ private trait BspWorker {

private object BspWorker {

private[this] var worker: Option[BspWorker] = None
private var worker: Option[BspWorker] = None

def apply(
workspace: os.Path,
Expand Down
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/BspTestReporter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ private class BspTestReporter(

// Compute the display name of the test / test suite
// to which the given event relates
private[this] def getDisplayName(e: Event): String = {
private def getDisplayName(e: Event): String = {
e.selector() match {
case s: NestedSuiteSelector => s.suiteId()
case s: NestedTestSelector => s.suiteId() + "." + s.testName()
Expand Down
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/BspWorkerImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ private class BspWorkerImpl() extends BspWorker {
}

val bspServerHandle = new BspServerHandle {
private[this] var lastResult0: Option[BspServerResult] = None
private var lastResult0: Option[BspServerResult] = None

override def runSession(evaluators: Seq[Evaluator]): BspServerResult = {
lastResult0 = None
Expand Down
10 changes: 5 additions & 5 deletions bsp/worker/src/mill/bsp/worker/MillBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private class MillBuildServer(

private[worker] var cancellator: Boolean => Unit = shutdownBefore => ()
private[worker] var onSessionEnd: Option[BspServerResult => Unit] = None
protected var client: BuildClient = _
protected var client: BuildClient = scala.compiletime.uninitialized
private var initialized = false
private var shutdownRequested = false
protected var clientWantsSemanticDb = false
Expand All @@ -57,7 +57,7 @@ private class MillBuildServer(
/** `true` when client and server support the `JvmCompileClasspathProvider` request. */
protected var enableJvmCompileClasspathProvider = false

private[this] var statePromise: Promise[State] = Promise[State]()
private var statePromise: Promise[State] = Promise[State]()

def updateEvaluator(evaluatorsOpt: Option[Seq[Evaluator]]): Unit = {
debug(s"Updating Evaluator: $evaluatorsOpt")
Expand Down Expand Up @@ -523,7 +523,7 @@ private class MillBuildServer(
.foldLeft(StatusCode.OK) { (overallStatusCode, targetId) =>
state.bspModulesById(targetId) match {
case (testModule: TestModule, ev) =>
val testTask = testModule.testLocal(argsMap(targetId.getUri): _*)
val testTask = testModule.testLocal(argsMap(targetId.getUri)*)

// notifying the client that the testing of this build target started
val taskStartParams = new TaskStartParams(new TaskId(testTask.hashCode().toString))
Expand Down Expand Up @@ -601,7 +601,7 @@ private class MillBuildServer(
}
val compileTargetName = (module.millModuleSegments ++ Label("compile")).render
debug(s"about to clean: ${compileTargetName}")
val cleanTask = mainModule.clean(ev, Seq(compileTargetName): _*)
val cleanTask = mainModule.clean(ev, Seq(compileTargetName)*)
val cleanResult = evaluate(
ev,
Strict.Agg(cleanTask),
Expand Down Expand Up @@ -806,7 +806,7 @@ private class MillBuildServer(

private def evaluate(
evaluator: Evaluator,
goals: Agg[Task[_]],
goals: Agg[Task[?]],
reporter: Int => Option[CompileProblemReporter] = _ => Option.empty[CompileProblemReporter],
testReporter: TestReporter = DummyTestReporter,
logger: ColorLogger = null
Expand Down
2 changes: 1 addition & 1 deletion bsp/worker/src/mill/bsp/worker/MillJvmBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ private trait MillJvmBuildServer extends JvmBuildServer { this: MillBuildServer
ev,
state,
id,
_: TestModule with JavaModule,
_: (TestModule & JavaModule),
(
_,
forkArgs,
Expand Down
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/MillScalaBuildServer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
}
) {
case (ev, state, id, m: TestModule, Some((classpath, testFramework, testClasspath))) =>
val (frameworkName, classFingerprint): (String, Agg[(Class[_], Fingerprint)]) =
val (frameworkName, classFingerprint): (String, Agg[(Class[?], Fingerprint)]) =
Jvm.withClassLoader(
classPath = classpath.map(_.path).toVector,
sharedPrefixes = Seq("sbt.testing.")
Expand All @@ -130,7 +130,7 @@ private trait MillScalaBuildServer extends ScalaBuildServer { this: MillBuildSer
Agg.from(testClasspath.map(_.path))
)
(framework.name(), discoveredTests)
}
}: @unchecked
val classes = Seq.from(classFingerprint.map(classF => classF._1.getName.stripSuffix("$")))
new ScalaTestClassesItem(id, classes.asJava).tap { it =>
it.setFramework(frameworkName)
Expand Down
4 changes: 2 additions & 2 deletions bsp/worker/src/mill/bsp/worker/Utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ private object Utils {
else Nil
}

private[this] def getStatusCodePerTask(
private def getStatusCodePerTask(
results: Evaluator.Results,
task: mill.define.Task[_]
task: mill.define.Task[?]
): StatusCode = {
results.results(task).result match {
case Success(_) => StatusCode.OK
Expand Down
10 changes: 6 additions & 4 deletions build.mill
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,8 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul
else ZincWorkerUtil.scalaBinaryVersion(sv)
}

def scalafixConfig = T {
if (ZincWorkerUtil.isScala3(scalaVersion())) Some(T.workspace / ".scalafix-3.conf") else None
}
def scalafixConfig = T { Some(T.workspace / ".scalafix.conf") }

def semanticDbVersion = Deps.semanticDBscala.version

def scaladocOptions = Seq("-Xsource:3")
Expand All @@ -492,6 +491,7 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul
// "-Wsafe-init",
// "-Wnonunit-statement",
// "-Wimplausible-patterns",
// "-rewrite", "-source", "3.6-migration"
)
else Seq(
"-P:acyclic:force",
Expand Down Expand Up @@ -524,7 +524,9 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul

/** Default tests module. */
lazy val test: MillScalaTests = new MillScalaTests {}
trait MillScalaTests extends ScalaTests with MillJavaModule with MillBaseTestsModule {
trait MillScalaTests extends ScalaTests with MillJavaModule with MillBaseTestsModule
with ScalafixModule {
def scalafixConfig = T { Some(T.workspace / ".scalafix.conf") }
def forkArgs = super.forkArgs() ++ outer.testArgs()
def moduleDeps = outer.testModuleDeps
def ivyDeps = super.ivyDeps() ++ outer.testIvyDeps()
Expand Down
59 changes: 34 additions & 25 deletions ci/mill-bootstrap.patch
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
diff --git a/build.mill b/build.mill
index 4f66e7cfeb7..1c608ae4d86 100644
index 70cfce14468..8ea29a961ab 100644
--- a/build.mill
+++ b/build.mill
@@ -1,9 +1,9 @@
Expand Down Expand Up @@ -48,7 +48,16 @@ index 4f66e7cfeb7..1c608ae4d86 100644
def scalaVersion = Deps.scalaVersion
def scalapVersion: T[String] = Deps.scala2Version
def scalafixScalaBinaryVersion = T {
@@ -561,7 +561,8 @@ trait MillBaseTestsModule extends TestModule {
@@ -525,7 +525,7 @@ trait MillScalaModule extends ScalaModule with MillJavaModule with ScalafixModul
/** Default tests module. */
lazy val test: MillScalaTests = new MillScalaTests {}
trait MillScalaTests extends ScalaTests with MillJavaModule with MillBaseTestsModule
- with ScalafixModule {
+ /*with ScalafixModule*/ {
def scalafixConfig = T { Some(T.workspace / ".scalafix.conf") }
def forkArgs = super.forkArgs() ++ outer.testArgs()
def moduleDeps = outer.testModuleDeps
@@ -565,7 +565,8 @@ trait MillBaseTestsModule extends TestModule {
trait MillPublishScalaModule extends MillScalaModule with MillPublishJavaModule

/** Publishable module which contains strictly handled API. */
Expand All @@ -58,7 +67,7 @@ index 4f66e7cfeb7..1c608ae4d86 100644
import com.github.lolgab.mill.mima._
override def mimaBinaryIssueFilters: T[Seq[ProblemFilter]] = Seq(
// (5x) MIMA doesn't properly ignore things which are nested inside other private things
@@ -691,7 +692,7 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima {
@@ -695,7 +696,7 @@ trait MillStableScalaModule extends MillPublishScalaModule with Mima {
def skipPreviousVersions: T[Seq[String]] = T {
T.log.info("Skipping mima for previous versions (!!1000s of errors due to Scala 3)")
mimaPreviousVersions() // T(Seq.empty[String])
Expand All @@ -68,7 +77,7 @@ index 4f66e7cfeb7..1c608ae4d86 100644

object bridge extends Cross[BridgeModule](compilerBridgeScalaVersions)
diff --git a/dist/package.mill b/dist/package.mill
index 67d3f94c143..98733778894 100644
index 5b8d77f5180..72f4963ce5f 100644
--- a/dist/package.mill
+++ b/dist/package.mill
@@ -3,7 +3,7 @@ import mill._, scalalib._, publish._
Expand Down Expand Up @@ -111,8 +120,28 @@ index 67d3f94c143..98733778894 100644
()
}

diff --git a/mill-build/build.mill b/mill-build/build.mill
index 957d929826d..112f1aaccb8 100644
--- a/mill-build/build.mill
+++ b/mill-build/build.mill
@@ -4,12 +4,12 @@ import mill.scalalib._

object `package` extends MillBuildRootModule {
override def ivyDeps = Agg(
- ivy"de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1",
- ivy"com.github.lolgab::mill-mima::0.1.1",
+// ivy"de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1",
+// ivy"com.github.lolgab::mill-mima::0.1.1",
ivy"net.sourceforge.htmlcleaner:htmlcleaner:2.29",
// TODO: implement empty version for ivy deps as we do in import parser
ivy"com.lihaoyi::mill-contrib-buildinfo:${mill.api.BuildInfo.millVersion}",
- ivy"com.goyeau::mill-scalafix::0.5.0",
+// ivy"com.goyeau::mill-scalafix::0.5.0",
ivy"com.lihaoyi::mill-main-graphviz:${mill.api.BuildInfo.millVersion}",
// TODO: document, why we have this dependency
ivy"org.jsoup:jsoup:1.18.1"
diff --git a/website/package.mill b/website/package.mill
index d558389312e..11f8e5c3ce9 100644
index eb4f1515dee..a49e72e84fe 100644
--- a/website/package.mill
+++ b/website/package.mill
@@ -40,8 +40,8 @@ object `package` extends RootModule {
Expand Down Expand Up @@ -164,23 +193,3 @@ index d558389312e..11f8e5c3ce9 100644
mainArgs = orderedDiagrams.map { case (p, i, src, dest) => s"$src;$dest;svg" }
)

diff --git a/mill-build/build.mill b/mill-build/build.mill
index 957d929826d..112f1aaccb8 100644
--- a/mill-build/build.mill
+++ b/mill-build/build.mill
@@ -4,12 +4,12 @@ import mill.scalalib._

object `package` extends MillBuildRootModule {
override def ivyDeps = Agg(
- ivy"de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1",
- ivy"com.github.lolgab::mill-mima::0.1.1",
+// ivy"de.tototec::de.tobiasroeser.mill.vcs.version::0.4.1",
+// ivy"com.github.lolgab::mill-mima::0.1.1",
ivy"net.sourceforge.htmlcleaner:htmlcleaner:2.29",
// TODO: implement empty version for ivy deps as we do in import parser
ivy"com.lihaoyi::mill-contrib-buildinfo:${mill.api.BuildInfo.millVersion}",
- ivy"com.goyeau::mill-scalafix::0.5.0",
+// ivy"com.goyeau::mill-scalafix::0.5.0",
ivy"com.lihaoyi::mill-main-graphviz:${mill.api.BuildInfo.millVersion}",
// TODO: document, why we have this dependency
ivy"org.jsoup:jsoup:1.18.1"
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ object ArtifactoryPublishModule extends ExternalModule {
connectTimeout,
Task.log
).publishAll(
artifacts: _*
artifacts*
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ object BintrayPublishModule extends ExternalModule {
connectTimeout,
Task.log
).publishAll(
Task.sequence(publishArtifacts.value)(): _*
Task.sequence(publishArtifacts.value)()*
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,13 +116,13 @@ object BuildInfoTests extends TestSuite {
EmptyBuildInfo,
testModuleSourcesPath / "scala"
).scoped { eval =>
val Right(_) = eval.apply(EmptyBuildInfo.buildInfoSources)
val Right(_) = eval.apply(EmptyBuildInfo.buildInfoSources): @unchecked
assert(!os.exists(buildInfoSourcePath(eval)))
}

test("fileGeneration") - UnitTester(BuildInfoComment, testModuleSourcesPath / "scala").scoped {
eval =>
val Right(_) = eval.apply(BuildInfoComment.compile)
val Right(_) = eval.apply(BuildInfoComment.compile): @unchecked

// Make sure that the buildinfo Scala file buildinfo is created and buildinfo
// resource file is *not* created when we compile the Scala code
Expand All @@ -145,7 +145,7 @@ object BuildInfoTests extends TestSuite {
}

// But becomes created once we package the jar for running
val Right(_) = eval.apply(BuildInfoComment.jar)
val Right(_) = eval.apply(BuildInfoComment.jar): @unchecked

val expectedResource = "mill.contrib.buildinfo.BuildInfo for foo."

Expand All @@ -158,7 +158,7 @@ object BuildInfoTests extends TestSuite {
BuildInfoSettings,
testModuleSourcesPath / "scala"
).scoped { eval =>
val Right(result) = eval.apply(BuildInfoSettings.buildInfoSources)
val Right(result) = eval.apply(BuildInfoSettings.buildInfoSources): @unchecked
val path = result.value.head.path

assert(os.exists(path / "foo/bar.scala"))
Expand All @@ -168,14 +168,14 @@ object BuildInfoTests extends TestSuite {
}

test("compile") - UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala").scoped { eval =>
val Right(_) = eval.apply(BuildInfoPlain.compile)
val Right(_) = eval.apply(BuildInfoPlain.compile): @unchecked
assert(true)
}

test("run") - UnitTester(BuildInfoPlain, testModuleSourcesPath / "scala").scoped { eval =>
val runResult = eval.outPath / "hello-mill"
val Right(_) =
eval.apply(BuildInfoPlain.run(Task.Anon(Args(runResult.toString))))
eval.apply(BuildInfoPlain.run(Task.Anon(Args(runResult.toString)))): @unchecked

assert(
os.exists(runResult),
Expand All @@ -185,7 +185,7 @@ object BuildInfoTests extends TestSuite {

test("scalajs") - UnitTester(BuildInfoScalaJS, testModuleSourcesPath / "scala-simple").scoped {
eval =>
val runResult = eval.outPath / "hello-mill"
eval.outPath / "hello-mill"
assert(eval.apply(BuildInfoScalaJS.fastLinkJS).isRight)
}

Expand All @@ -195,7 +195,7 @@ object BuildInfoTests extends TestSuite {
val runResult = eval.outPath / "hello-mill"

val Right(_) =
eval.apply(BuildInfoStatic.run(Task.Anon(Args(runResult.toString))))
eval.apply(BuildInfoStatic.run(Task.Anon(Args(runResult.toString)))): @unchecked

assert(os.exists(buildInfoSourcePath(eval)))
assert(!os.exists(buildInfoResourcePath(eval)))
Expand All @@ -206,7 +206,7 @@ object BuildInfoTests extends TestSuite {
test("java") - UnitTester(BuildInfoJava, testModuleSourcesPath / "java").scoped { eval =>
val runResult = eval.outPath / "hello-mill"
val Right(_) =
eval.apply(BuildInfoJava.run(Task.Anon(Args(runResult.toString))))
eval.apply(BuildInfoJava.run(Task.Anon(Args(runResult.toString)))): @unchecked

assert(
os.exists(runResult),
Expand All @@ -219,7 +219,7 @@ object BuildInfoTests extends TestSuite {
val runResult = eval.outPath / "hello-mill"
val generatedSrc = eval.outPath / "buildInfoSources.dest/foo/BuildInfo.java"
val Right(_) =
eval.apply(BuildInfoJavaStatic.run(Task.Anon(Args(runResult.toString))))
eval.apply(BuildInfoJavaStatic.run(Task.Anon(Args(runResult.toString)))): @unchecked

assert(
os.exists(runResult),
Expand All @@ -233,7 +233,7 @@ object BuildInfoTests extends TestSuite {
testModuleSourcesPath / "scala"
).scoped { eval =>
val buildInfoGeneratedSourcesFolder = eval.outPath / "buildInfoSources.dest"
val Right(result) = eval.apply(BuildInfoPlain.generatedSources)
val Right(result) = eval.apply(BuildInfoPlain.generatedSources): @unchecked
assert(
result.value.size == 1,
os.isDir(result.value.head.path),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ object CodeartifactPublishModule extends ExternalModule {
connectTimeout,
Task.log
).publishAll(
artifacts: _*
artifacts*
)
}

Expand Down
Loading

0 comments on commit be14d4e

Please sign in to comment.