-
Notifications
You must be signed in to change notification settings - Fork 17
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
Changes from 1 commit
afd488d
29a274c
8b31cd4
ad4b594
1df01e0
6cd080e
cb02ca1
2478d47
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
rules = [ | ||
ExplicitResultTypes | ||
] |
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) | ||
} |
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
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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. | ||
|
@@ -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(), | ||
|
@@ -63,6 +66,7 @@ object ScalafixModule { | |
os.pwd | ||
) | ||
|
||
@nowarn("msg=parameter scalaBinaryVersion in method fixAction is never used") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
def fixAction( | ||
log: Logger, | ||
repositories: Seq[Repository], | ||
|
@@ -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) | ||
|
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.