scalafix icon indicating copy to clipboard operation
scalafix copied to clipboard

Let rules expose scala versions constraints

Open bjaglin opened this issue 5 years ago • 0 comments
trafficstars

Advanced semantic rules such as ExplicitResultTypes or ExplicitNonNullaryApply using the presentation compiler via ScalafixGlobal require the build scalaVersion to match scalafixScalaBinaryVersion, and potentially the full Scala release used by Scalafix.

Rules themselves should not suggest actions to fix a mismatch (as rules might not be run from sbt for example). That should be up to the rules runner (mill, sbt, CLI, metals, etc), which should be able to intercept information upon execution failure and derive a relevant call for action, or even update state automatically (maybe with a warning saying it should be made persistent).

Implementation: I am not sure the return type of https://www.javadoc.io/static/ch.epfl.scala/scalafix-core_2.12/0.9.18/scalafix/v1/SemanticRule.html#withConfiguration(config:scalafix.v1.Configuration):metaconfig.Configured[scalafix.v1.Rule] is rich enough to allow that level of information, so we need to discuss how this could be implemented in a backward-compatible way. Suggestion:

// Rule.scala

 // making it non-sealed will force clients to pattern-match `_` and be forward compatible
/*sealed*/ trait InputRequirement
case class BinaryScalaVersion(binaryScalaVersion: String) extends InputRequirement
case class ScalaVersion(scalaVersion: String) extends InputRequirement
case class RequiredScalacOption(scalacOption: String) extends InputRequirement
case class IncompatibleScalacOption(scalacOption: String) extends InputRequirement
...

protected def failedRequirements(
  inputScalaVersion: String,
  inputScalacOptions: String
): List[InputCompilationRequirement]) = Nil

Somewhat related to https://github.com/scalacenter/scalafix/issues/1143

bjaglin avatar Jul 03 '20 23:07 bjaglin