Releases: scalacenter/scalafix
Scalafix v0.5.0-RC3
New features for end-users
This release introduces major improvements to sbt-scalafix, scalafix-cli.
sbtfix
task in sbt-scalafix to run rules on build sources.- Sbt1 rule to migrate usage of deprecated sbt 0.13 APIs, by @jvican.
- NoInfer linter that reports errors when the compiler reports types such as
Any
- ExplicitResultTypes experimental
unsafeShortenNames
option to insert imports instead of fully qualified names. - Scala.js support for scalafix-core, by @gabro.
- Configurable ExplicitResultTypes, by @taisuke.
- Configurable lint reporting.
- sbt-scalafix rule tab completion.
- scalafix-cli
--zsh
and--bash
to generate tab completion scripts for zsh and bash. - replace: to run quick one-off refactorings.
New features for rule authors
- Ability to implement rules for sources of sbt builds, including
*.sbt
files. The API to write sbt rules is identical to regular Scala rules. - Rules can now emit lint messages with
ctx.lint
, see LintMessage. - Thanks to upstream improvements in the Scalameta v2.0 Semantic API, it is now possible to
- query symbols of implicit arguments, implicit conversions, type parameters,
.apply
/.unapply
and symbol signatures. This represents significant portion of the work for Scalafix v0.5 and is a major milestone for the Scalameta semantic API. - parse symbols signatures as
scala.meta.Type
, including the newType.Method
which is the "type of methods" and cannot be written in source.
- query symbols of implicit arguments, implicit conversions, type parameters,
Rule.init(config): Configured[Rule]
allows rules to load the user configuration during rule construction. Before, rules had to parse the configuration while fixing each individual file.PatchOps.replaceSymbol/replaceTree
, see Patch.- PatchOps now has docstrings!
- Rules can have multiple names with optional deprecation warnings.
Bug fixes / Improvements
- ExplicitResultTypes produces valid type signatures in a lot more cases than before. Note that it still has some known bugs, see #324.
- More robust classloading to invoke scalafix in sbt-scalafix. Previously, sbt-scalafix used synthetic projects which cause problem in some multi-module builds. Now, sbt-scalafix uses Coursier instead.
- Improved dynamic compilation of custom rules while running from multi-module sbt builds.
- Extension methods now resolve to the correct symbol. For example,
head
inArray[Int].head
previously resolved toPredef.intArrayOps
and now it resolves toIndexedSeqOptimized.head
. - scalafix-cli automatically infers whether passed --rewrites are semantic or syntactic. This means it's possible to run custom syntactic rules from scalafix-cli without passing in
--classpath
.
Breaking changes
From 0.5 onwards, our CI will check binary breaking changes in the public API on every pull request. Note that modules inside the package scalafix.internal
don't promise binary compatibility between any releases, including PATCH upgrades.
-
github:
rewrites should be inside thescalafix/rules/...
directory instead ofscalafix/rewrites/...
directory -
scalafix.Rewrite/SemanticRewrite
is now deprecated andMirror
is nowSemanticdbIndex
.// before case class MyRewrite(mirror: Mirror) extends SemanticRewrite(mirror) { def rewrite(ctx: RewriteCtx): Patch } // before case class MyRule(index: SemanticdbIndex) extends SemanticRule(index) { def fix(ctx: RewriteCtx): Patch }
-
scalafix.testkit.SemanticRewriteSuite
is now nowSemanticRuleSuite
. -
scalafix.config
has been moved toscalafix.internal.config
. Configuration case classes break binary compatility with every new field. -
.symbol
now returnsOption[Symbol]
instead ofSymbol
..symbolOpt
has been deprecated. -
A large number of unused methods and classes inside
scalafix.internal.util.Failure
,scalafix.`package`
andscalafix.syntax
has been removed. -
upgraded to Scalameta 2.0, which has several breaking changes in the Tree api.
-
The
VolatileLazyVal
rule is now named DottyVolatileLazyVal.
Contributors
git shortlog -sn --no-merges v0.4.2..v0.5.0-RC3
shows 5 people contributed to this release.
- Ólafur Páll Geirsson
- Gabriele Petronella
- Guillaume Massé
- Taisuke Oe
- Andy Scott
Scalafix 0.4.2
- Fixed #200, thank you @xuwei-k for reporting.
- New section documenting how to implement rules, see Creating your own rule, in particular https://scalacenter.github.io/scalafix/#scalacenter/scalafix.g8
v0.4.1
First of all, I'd like to welcome Gabriele Petronella, @gabro, to the scalafix team! See #184.
- New rule
NoExtendsApp
(removed in v0.5), by @gabro. - New rule DottyVarArgPattern, by @gosubpl.
- Errors in the scalafix-testkit docs have now been fixed, by @taisukeoe.
--sourceroot
is now used by scalafix-cli, #176.--sourcepath
is no longer used by scalafix-cli.- NoAutoTupling now handles Function1 signatures, see #147.
- scalafix-cli now supports
--include
and--exclude
to filter which files get fixed. See --help for more details. - RemoveUnusedImports now also removes unused renamed imports, see #189.
Big thanks you everybody who contributed this release via issues, pull requests, online discussions on Gitter.
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
v0.3.4
- New
RenameSymbol
tree patch, which behaves similar to "Rename method/variable" refactorings in IDEs. - New module: scalafix-testkit.
- Rules can now report info/warn/error messages via
ctx.reporter.info/warn/error
, see #118. - 2.11 support is now only for 2.11.10.
Scalafix 0.3.3
-
NOTE. scalafix-core and scalafix-cli are now published as
CrossVersion.full
, meaning the artifact IDs now have a_2.11.11
suffix. To depend on them,// OK libraryDependencies += "ch.epfl.scala" % "scalafix-core" % "0.5.0-RC3" cross CrossVersion.full // Error libraryDependencies += "ch.epfl.scala" %% "scalafix-core" % "0.5.0-RC3"
-
NOTE. This version depends on a pre-release of scala.meta, which is publised to the scalameta bintray repository and requires
resolvers += Resolver.bintrayRepo("scalameta", "maven")
-
scalafix-cli new supports running semantic rules with the
--classpath/--sourcepath
options. -
scalafix-cli now supports
.sbt
files. -
New documentation for scalafix-cli.
Scalafix 0.3.2
See merged PRs.
- It is possible to load custom rules from source with
rules = ["file:MyRule.scala"]
or urlsrules = ["https://gist./../.Rule.scala"]
. imports.groups = []
can now be empty, thank you @mlangc for contributing this fix!- Named imports are no longer subsumed by wildcard imports, which could previously introduce ambiguous imports.
imports.expandRelative = false
by default. Expanded relative imports can create unused imports. If you want to expand relative imports, you may need to run scalafix twice to remove unused imports created by scalafix.- Fixed minor ordering bugs in organize imports.
Scalafix 0.3.1
- Fixed a bug in organize imports when there was no import in the original source file.
- Patch.apply and OrganizeImports no longer accept a redundant
tree: Tree
argument, thectx
already contains the tree. - Xor2Either is disabled by default now, it was enabled by default causing the
scalafix
command to slow down significantly. Rules usingscala.meta.Mirror
should not experience a slowdown. - Added new
Rename(from: Name, to: Name)
tree patch that's accesible via the scalafix-library.
Scalafix 0.3.0
-
Scalafix now uses the scala.meta semantic API! See scala.meta 1.6 release notes for more details about the semantic api. This first release of the scala.meta semantic API enables rules to query for the "symbol" of a name that appears in a Scala source file. A symbol is a unique identifier of a definition such as a class, val, def or trait.
-
To demonstrate the capabilities of rules using the scala.meta semantic API, we have included an example rule called Xor2Either. The rule migrates usage of
cats.data.Xor
toscala.util.Either
. -
Rules can now be implemented in terms of "tree patches", which are high level descriptions of common refactoring operations. Tree patches can be composed to build more advanced refactorings such as
Xor2Either
. The current available tree patches areReplace
: Replaces usage of a symbol with another name.AddGlobalImport
: Adds a top-level import to source file.RemoveGlobalImport
: Removes a top-level import from source file.
Special thanks go to @ShaneDelmore for helping out try the scalafix patch API at every step of its development. His feedback has been invaluable in improving the design of the API.
-
Configuration in .scalafix.conf has been greatly improved to support a wide range of options. Examples, see patches,
imports
(now removed) andAll options
(removed).
Scalafix 0.2.1
sbt scalafix
runsExplicitImplicit
andProcedureSyntax
by default when there is no.scalafix.conf
.- Upgraded scala.meta dependency to fix parsing + pretty-printer bugs.