Skip to content

Commit

Permalink
Make Scalafix look for config in T.workspace rather than os.pwd (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
lihaoyi authored Aug 28, 2024
1 parent 9f01482 commit 16019d6
Showing 1 changed file with 34 additions and 7 deletions.
41 changes: 34 additions & 7 deletions mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@ import mill.{Agg, T}
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.*

trait ScalafixModule extends ScalaModule {
def scalafixConfig: T[Option[Path]] = T(None)
def scalafixConfig: T[Option[os.Path]] = T(None)
def scalafixIvyDeps: T[Agg[Dep]] = Agg.empty[Dep]
def scalafixScalaBinaryVersion: T[String] = "2.12"

Expand All @@ -31,7 +31,8 @@ trait ScalafixModule extends ScalaModule {
scalacOptions(),
scalafixIvyDeps(),
scalafixConfig(),
args*
args,
T.workspace
)
}
}
Expand All @@ -40,21 +41,47 @@ object ScalafixModule {
def fixAction(
log: Logger,
repositories: Seq[Repository],
sources: Seq[Path],
classpath: Seq[Path],
sources: Seq[os.Path],
classpath: Seq[os.Path],
scalaVersion: String,
scalaBinaryVersion: String,
scalacOptions: Seq[String],
scalafixIvyDeps: Agg[Dep],
scalafixConfig: Option[Path],
scalafixConfig: Option[os.Path],
args: String*
): Result[Unit] = fixAction(
log,
repositories,
sources,
classpath,
scalaVersion,
scalaBinaryVersion,
scalacOptions,
scalafixIvyDeps,
scalafixConfig,
args,
os.pwd
)

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] =
if (sources.nonEmpty) {
val scalafix = Scalafix
.fetchAndClassloadInstance(scalaBinaryVersion, repositories.map(CoursierUtils.toApiRepository).asJava)
.newArguments()
.withParsedArguments(args.asJava)
.withWorkingDirectory(pwd.toNIO)
.withWorkingDirectory(wd.toNIO)
.withConfig(scalafixConfig.map(_.toNIO).asJava)
.withClasspath(classpath.map(_.toNIO).asJava)
.withScalaVersion(scalaVersion)
Expand Down

0 comments on commit 16019d6

Please sign in to comment.