Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pass scalaVersion to Scalafix as needed for Scalafix 0.13.0 #205

Merged
merged 8 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
),
Comment on lines +61 to +64
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just saw tests were failing because of that boyscout-rule addition, independently of the actual purpose of this PR 🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The tests were not running. I could do this in a separate PR but honestly I don't see the reason.

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"))
),
Expand Down
3 changes: 3 additions & 0 deletions itest/src/fix-3.5/.scalafix.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
rules = [
ExplicitResultTypes
]
20 changes: 20 additions & 0 deletions itest/src/fix-3.5/build.sc
Original file line number Diff line number Diff line change
@@ -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)
lolgab marked this conversation as resolved.
Show resolved Hide resolved
assert(fixedScala == expected)
}
3 changes: 3 additions & 0 deletions itest/src/fix-3.5/project/src/Fix.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
object Fix {
def myComplexMethod = 1.to(10).map(i => i -> i.toString).toMap
lolgab marked this conversation as resolved.
Show resolved Hide resolved
}
12 changes: 8 additions & 4 deletions mill-scalafix/src/com/goyeau/mill/scalafix/ScalafixModule.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(),
Expand Down Expand Up @@ -63,6 +66,7 @@ object ScalafixModule {
os.pwd
)

@nowarn("msg=parameter scalaBinaryVersion in method fixAction is never used")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assume you left the parameter for binary compatibility in the patch line? Nitpicking: we could create an overload (easier to clear later) and get rid of the propagation of scalafixScalaBinaryVersion for the real code path.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

def fixAction(
log: Logger,
repositories: Seq[Repository],
Expand All @@ -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)
Expand Down
Loading