Skip to content

Commit

Permalink
Support Mill 0.11
Browse files Browse the repository at this point in the history
  • Loading branch information
joan38 committed Jun 26, 2023
1 parent 2da44e8 commit 51ac6d0
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 70 deletions.
9 changes: 2 additions & 7 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import de.tobiasroeser.mill.integrationtest._
import io.github.davidgregory084.TpolecatModule
import mill._
import mill.contrib.buildinfo.BuildInfo
import mill.scalalib.api.Util.scalaNativeBinaryVersion
import mill.scalalib.api.ZincWorkerUtil.scalaNativeBinaryVersion
import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}
import scalalib._

val millVersions = Seq("0.10.12")
val millVersions = Seq("0.10.12", "0.11.1")
def millBinaryVersion(millVersion: String) = scalaNativeBinaryVersion(millVersion)

object `mill-scalafix` extends Cross[MillScalafixCross](millVersions: _*)
Expand All @@ -25,8 +25,6 @@ class MillScalafixCross(millVersion: String)
with GitVersionedPublishModule {
override def crossScalaVersion = "2.13.10"
override def artifactSuffix = s"_mill${millBinaryVersion(millVersion)}" + super.artifactSuffix()
override def scalacOptions =
super.scalacOptions().filterNot(opt => millVersion.startsWith("0.10") && opt == "-Xfatal-warnings")

override def compileIvyDeps = super.compileIvyDeps() ++ Agg(
ivy"com.lihaoyi::mill-main:$millVersion",
Expand Down Expand Up @@ -74,9 +72,6 @@ class ITestCross(millVersion: String) extends MillIntegrationTestModule {
PathRef(sources().head.path / "custom-rule") -> Seq(
TestInvocation.Targets(Seq("__.fix")),
TestInvocation.Targets(Seq("verify"))
),
PathRef(sources().head.path / "no-source") -> Seq(
TestInvocation.Targets(Seq("__.fix"))
)
)
}
4 changes: 2 additions & 2 deletions itest/src/check-failed/build.sc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import $exec.plugins
import $file.plugins
import com.goyeau.mill.scalafix.ScalafixModule
import mill.scalalib._

object project extends ScalaModule with ScalafixModule {
def scalaVersion = "2.13.6"
def scalaVersion = "2.13.10"
def scalacOptions = Seq("-Ywarn-unused")
}
2 changes: 1 addition & 1 deletion itest/src/check/build.sc
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import $exec.plugins
import $file.plugins
import com.goyeau.mill.scalafix.ScalafixModule
import mill.scalalib._

Expand Down
6 changes: 3 additions & 3 deletions itest/src/custom-rule/build.sc
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import $exec.plugins
import $file.plugins
import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.scalalib._
import os._

object project extends ScalaModule with ScalafixModule {
def scalaVersion = "2.13.3"
def scalaVersion = "2.13.10"
def scalacOptions = Seq("-Ywarn-unused", "-Yrangepos", "-P:semanticdb:synthetics:on")
def scalafixIvyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-migrations:2.2.0")
def scalafixIvyDeps = Agg(ivy"org.scala-lang.modules::scala-collection-migrations:2.11.0")
}

def verify() =
Expand Down
4 changes: 2 additions & 2 deletions itest/src/fix-2.12/build.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import $exec.plugins
import $file.plugins
import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.scalalib._
import os._

object project extends ScalaModule with ScalafixModule {
def scalaVersion = "2.12.11"
def scalaVersion = "2.12.17"
def scalacOptions = Seq("-Ywarn-unused")
}

Expand Down
4 changes: 2 additions & 2 deletions itest/src/fix/build.sc
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import $exec.plugins
import $file.plugins
import com.goyeau.mill.scalafix.ScalafixModule
import mill._
import mill.scalalib._
import os._

object project extends ScalaModule with ScalafixModule {
def scalaVersion = "2.13.6"
def scalaVersion = "2.13.10"
def scalacOptions = Seq("-Ywarn-unused")
}

Expand Down
18 changes: 0 additions & 18 deletions itest/src/no-source/.scalafix.conf

This file was deleted.

8 changes: 0 additions & 8 deletions itest/src/no-source/build.sc

This file was deleted.

34 changes: 10 additions & 24 deletions mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ package com.goyeau.mill.scalafix
import com.goyeau.mill.scalafix.ScalafixModule.{filesToFix, fixAction}
import coursier.Repository
import mill.{Agg, T}
import mill.api.{Logger, Loose, PathRef, Result}
import mill.scalalib.{Dep, DepSyntax, ScalaModule}
import mill.define.{Command, Target}
import os._
import mill.api.{Logger, PathRef, Result}
import mill.scalalib.{Dep, ScalaModule}
import mill.define.Command
import os.*
import scalafix.interfaces.Scalafix
import scalafix.interfaces.ScalafixError._
import scala.compat.java8.OptionConverters._
import scala.jdk.CollectionConverters._
import scalafix.interfaces.ScalafixError.*
import scala.compat.java8.OptionConverters.*
import scala.jdk.CollectionConverters.*

trait ScalafixModule extends ScalaModule {
def scalafixConfig: T[Option[Path]] = T(None)
Expand All @@ -19,17 +19,8 @@ trait ScalafixModule extends ScalaModule {

/** Run Scalafix.
*/
def fix(args: String*): Command[Unit] = {
val isMillVersionSupported = mill.BuildInfo.millVersion match {
case s"$_.$minor.$patchWithSuffix" =>
val patch = patchWithSuffix.takeWhile(_.isDigit)
minor.toInt >= 10 && patch.toInt >= 6
case other =>
System.err.println(s"mill-scalafix: Failed to parse Mill $other version. Assuming it's supported.")
true
}

if (isMillVersionSupported) T.command {
def fix(args: String*): Command[Unit] =
T.command {
fixAction(
T.ctx().log,
repositoriesTask(),
Expand All @@ -40,14 +31,9 @@ trait ScalafixModule extends ScalaModule {
scalacOptions(),
scalafixIvyDeps(),
scalafixConfig(),
args: _*
args*
)
}
else
T.command[Unit] {
Result.Failure("Mill version not supported. Please update to Mill 0.10.6+")
}
}
}

object ScalafixModule {
Expand Down
3 changes: 0 additions & 3 deletions mill-scalafix/src/com/goyeau/mill/scalafix/StyleModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,16 @@ package com.goyeau.mill.scalafix
import mill.T
import mill.define.Command
import mill.scalalib.scalafmt.ScalafmtModule
import scala.annotation.nowarn

/** Combine Scalafmt and Scalafix together
*/
trait StyleModule extends ScalafmtModule with ScalafixModule {
@nowarn("msg=pure expression does nothing")
def style(): Command[Unit] =
T.command {
reformat()()
fix()()
}

@nowarn("msg=pure expression does nothing")
def checkStyle(): Command[Unit] =
T.command {
checkFormat()()
Expand Down

0 comments on commit 51ac6d0

Please sign in to comment.