Scalafix 0.4.0
This release represents a significant milestone for Scalafix. Scalafix no longer runs as a compiler plugin as it did in previous releases. Instead, Scalafix runs now independently from the compiler, and uses the Scalameta Semantic API to query information from the compiler.
New features
- New rule RemoveUnusedImports, by @olafurpg.
- New rule RemoveXmlLiterals, by @allanrenucci.
- New rule NoAutoTupling, by @gabro.
- New rule ExplicitUnit, by @gabro.
- New rule NoValInForComprehension, by @gabro.
- New github: protocol for loading rules, by @gabro.
- Improved scalafix-testkit, by @olafurpg.
- Simplified Rule API. The public API has shrunk down to four types:
Rule
,Patch
,ScalafixConfig
andRuleCtx
. The type parameters onRule
andRuleCtx
have been removed. A singleimport scalafix._
is enough get started with rules. - See the Scalameta Semantic API.
Breaking changes
-
The
scalafix-nsc
compiler plugin has been removed in favor of the Scalameta Semantic DB, that is emitted by the Scalametasemanticdb-scalac
compiler plugin. This change enables Scalafix rules to run separately from compilation. This means that running scalafix will be much faster, since it no longer requires creating a custom instance of the Scala compiler and re-typechecking an entire project. Scalafix reads all of its inputs from.semanticdb
files that are created by the semanticdb-scalac compiler plugin during regular compilation. -
The signature of
Rule.rule
has been simplified// before def rule[T](ctx: RuleCtx[T]): Seq[Patch] // after def rule(ctx: RuleCtx): Patch // a Seq[Patch] can be converted into Patch with .asPatch Seq[Patch]().asPatch: Patch
-
RuleCtx.mirror
has been removed. To write semantic rules, acceptSemanticCtx
as a constructor parameter instead// before case object MySemanticRule extends Rule { def rule[T](ctx: RuleCtx[T]): Seq[Patch] } // after case class MySemanticRule(index: SemanticdbIndex) extends SemanticRule(index) { def rule(ctx: RuleCtx): Patch }
-
scalafix.patch.TreePatch.{AddGlobalImport, RemoveGlobalImport, Replace, ...
} have been madeprivate[scalafix]
. Instead, use the provided operations onctx: RuleCtx
.// before TokenPatch.AddGlobalImport(importer"scala.meta._") // after ctx.addGlobalImport(importer"scala.meta._")
The motivation for this change was to statically enforce that a
SemanticCtx
is in scope during Patch creation. For the full available API of patch operations, see SemanticPatchOps -
The following configuration options have been removed
imports.removeUnusedImports // replaced by RemoveUnusedImports rule. // These were wishful thinking, too eagerly merged. imports.organizeImports imports.expandRelative imports.groupByPrefix
-
scalafix-cli now enabled the
--in-place (-i)
flag by default. Use--stdout
to print to standard output. -
scalafix-testkit no longer reads tests from
.source
files. Instead, tests are written in regular.scala
files that are compiled through sbt or another build tool. See scalafix-testkit for how to use it.
git shortlog -sn --no-merges v0.3.0..v0.4.0
tells us that 4 people contributed to this release:
- Ólafur Páll Geirsson
- Gabriele Petronella
- Allan Renucci
- Matthias Langer