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

Feed to whole classpath to scalafix and fix ExplicitResultTypes #172

Merged
merged 7 commits into from
Jan 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import mill.scalalib.api.ZincWorkerUtil.scalaNativeBinaryVersion
import mill.scalalib.publish.{Developer, License, PomSettings, VersionControl}
import scalalib._

val millVersions = Seq("0.10.12", "0.11.1")
val millVersions = Seq("0.10.15", "0.11.0")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We depend on new API since Mill 0.10.15.

def millBinaryVersion(millVersion: String) = scalaNativeBinaryVersion(millVersion)

object `mill-scalafix` extends Cross[MillScalafixCross](millVersions)
Expand Down
2 changes: 1 addition & 1 deletion itest/src/check/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ 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"
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Necessary to make test succeed.

def scalacOptions = Seq("-Ywarn-unused")
}
2 changes: 1 addition & 1 deletion itest/src/custom-rule/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import os._

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

Expand Down
3 changes: 2 additions & 1 deletion itest/src/fix/.scalafix.conf
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ rules = [
DisableSyntax
LeakingImplicitClassVal
NoValInForComprehension
ProcedureSyntax
ProcedureSyntax,
ExplicitResultTypes
]

DisableSyntax.noVars = true
Expand Down
2 changes: 2 additions & 0 deletions itest/src/fix/build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import os._

object project extends ScalaModule with ScalafixModule {
def scalaVersion = "2.13.10"
def scalafixScalaBinaryVersion = mill.scalalib.api.ZincWorkerUtil.scalaBinaryVersion(scalaVersion())
def scalacOptions = Seq("-Ywarn-unused")
}

Expand All @@ -14,6 +15,7 @@ def verify() =
val fixedScala = read(pwd / "project" / "src" / "Fix.scala")
val expected = """object Fix {
| def procedure(): Unit = {}
| def myComplexMethod: Map[Int,String] = 1.to(10).map(i => i -> i.toString).toMap
|}
|""".stripMargin
assert(fixedScala == expected)
Expand Down
1 change: 1 addition & 0 deletions itest/src/fix/project/src/Fix.scala
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
object Fix {
def procedure() {}
def myComplexMethod = 1.to(10).map(i => i -> i.toString).toMap
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ trait ScalafixModule extends ScalaModule {
T.ctx().log,
repositoriesTask(),
filesToFix(sources()).map(_.path),
Seq(semanticDbData().path),
classpath = (compileClasspath() ++ localClasspath() ++ Seq(semanticDbData())).iterator.toSeq.map(_.path),
Copy link
Contributor

Choose a reason for hiding this comment

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

A potential further improvement to reduce the added overhead would be to avoid triggering any compilation if none of the rules is semantic (rulesThatWillRun.exists(_.kind.isSemantic)) like it's done in sbt-scalafix. Not sure how/if this (dynamic tasks in sbt) can be achieved in Mill.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Could be tricky, as the task graph can't be changed once it has started. But we have some options at construction time, depending on how lightweight (fast) a check can be.

Anyways, this should be done in a separate PR.

scalaVersion(),
scalafixScalaBinaryVersion(),
scalacOptions(),
Expand Down
Loading