Add Scalafix integration - #283
Conversation
| ThisBuild / scalafixDependencies ++= Seq( | ||
| "com.github.liancheng" %% "organize-imports" % "0.6.0" | ||
| ) |
There was a problem hiding this comment.
Among other reasons not to tie sbt-typelevel compatibility to the organize-imports version, it hasn't been released against the latest scalafix yet.
| semanticdbEnabled := true, | ||
| semanticdbVersion := scalafixSemanticdb.revision, | ||
| scalafixScalaBinaryVersion := CrossVersion.binaryScalaVersion(scalaVersion.value), |
There was a problem hiding this comment.
Question: why doesn't the scalafix plugin do these settings?
There was a problem hiding this comment.
I'm really not sure - I suppose they are thinking about folks who only want to enable Scalafix selectively, but surely they would just disable the Scalafix plugin instead
| override def buildSettings = Seq[Setting[_]]( | ||
| semanticdbEnabled := true, | ||
| semanticdbVersion := scalafixSemanticdb.revision, | ||
| scalafixScalaBinaryVersion := scalaBinaryVersion.value, |
There was a problem hiding this comment.
The docs say:
val scalafixScalaBinaryVersion: SettingKey[String] =
settingKey[String](
"The Scala binary version used for scalafix execution. Must be set in ThisBuild. "
+ "Defaults to 2.12. Rules must be compiled against that binary version, or for "
+ "advanced rules such as ExplicitResultTypes which have a full cross-version, "
+ "against the corresponding full version that scalafix is built against."
)I'm skeptical if we should set this value to "3", ever.
There was a problem hiding this comment.
I did a survey of projects using scalafix and not all of them set this. For example, it seems the organize imports rule works fine with the default "2.12". So let's remove it for now.
| scalafixScalaBinaryVersion := scalaBinaryVersion.value, |
There was a problem hiding this comment.
Yup, organize imports isn't even published for Scala 3.
https://repo1.maven.org/maven2/com/github/liancheng/
There was a problem hiding this comment.
I think the binary version is important for semantic rules (and I suppose organize imports is semantic), but I guess perhaps for the purposes of organizing plain imports the differences between Scala versions are not that relevant.
There was a problem hiding this comment.
Ah I think I understand this a bit better now https://contributors.scala-lang.org/t/scalafix-future/4247/4?u=davidgregory084
There was a problem hiding this comment.
So I think the reason for the Scalafix binary version is for rules which directly use scalac APIs
There was a problem hiding this comment.
Ah, thanks, that was helpful.
In order not to break compatibility, while scalafix is still v0.9.x, the
scalafixScalaBinaryVersionis set by default to 2.12. In other words, if this key is not specified, 2.12 rules are still being used. But going further, and starting v1, our goal is to change the default value to follow the target sources version.
So it sounds like when the time is right, Scalafix itself will change this default. We could do it too, when enough rules are published against Scala 3.
|
Thanks for backporting this @armanbilge! Sorry for holding things up - took advantage of public holidays to get a full week off 😆 |
|
@DavidGregory084 good for you!! 😁 Not at all, I appreciate all your work here and on the snapshot API PRs, they've turned out quite nicely :) |
Backporting #274 into series/0.4. Closes #236. Closes #274.