scalafix
scalafix copied to clipboard
Better support for cross compilation
It is kind of a pain to use scalafix with an sbt project that is cross compiled for Scala 2 and 3 because scalafix has a hard fail if given a rule that isn't supported for that Scala version. For example:
[error] (web / Compile / scalafix) scalafix.sbt.InvalidArgument: 2 errors
[error] [E0] This rule is specific to Scala 2, because the compiler option `-Ywarn-unused` is not available yet in scala 3 To fix this error, remove RemoveUnused from .scalafix.conf
[error] [E1] This rule is specific to Scala 2, since procedure syntax is not supported in Scala 3. To fix this error, remove ProcedureSyntax from .scalafix.conf
Removing the rule from Scala 2 is unsatisfactory so the only other solution seems to be to have two separate configuration files. I didn't see any include functionality so this would have to be a copy/paste and both files have to be kept in sync.
It would be nice to have better support for having a single configuration that is used for multiple Scala versions.
A few thoughts come to mind:
- Change it to a warning instead of an error
- Add an
includefeature to the config so that common configuration could be shared - Make parts of the configuration conditional based on the Scala version
Thanks for reaching out!
First of all, it's worth noting that initial support for RemoveUnused is around the corner, in time for Scala 3.3.0, so hopefully this will be a little less needed soon.
Add an
includefeature to the config so that common configuration could be shared
Actually, scalafix relies on metaconfig, which has precisely support for that through HOCON. So you should be able to create a common configuration file included by scala-specific configuration files, and use them with something like
scalafixConfig := Some(file(s".scalafix-scala${scalaBinaryVersion.value}.conf"))
Would that work for you? If so, we could add a dedicated section to document that in https://github.com/scalacenter/scalafix/blob/main/docs/users/installation.md. PR with a reference to a real example usage would be very much welcome!