API Overview
Compatibility considerations
scalafix-core
makes the packages below available to built-in and external rules.
Its X.Y.Z version scheme follows Early SemVer for binary compatiblity and aims at keeping source compatibility across versions.
- Running a rule built against an older X or 0.Y version of Scalafix may cause either runtime errors, or false positive/negative tree selection. In that case, a warning calling the user to use a more recent version of the rule or downgrading Scalafix is issued when resolving the rules(s) artifact(s).
- Running a rule built against a more recent X.Y or 0.Y.Z version of Scalafix is also a potential source of incompatibility. In that case, a warning calling the user to upgrade Scalafix is issued when resolving the rules(s) artifact(s).
Packages
The Scalafix public API documentation is composed of several packages.
Scalafix v1
Latest Scaladoc: v0.14.4
The Scalafix v1 API is available through import scalafix.v1._. Key data
structures include:
Patch: to describe source code rewrites such as removing or replacing tokens and trees.SymbolMatcher: to match tree nodes that resolve to a specific set of symbols.SemanticType: a sealed data structure that encodes the Scala type system.SemanticTree: a sealed data structure that encodes tree nodes that are generated by the compiler from inferred type parameters, implicit arguments, implicit conversions, inferred.applyand for-comprehensions.Symbol: a unique identifier for a definition. For example, theStringclass has the symboljava/lang/String#. The type alias toStringin the Scala standard library has the symbolscala/Predef.String#.SymbolInformation: a data structure containing metadata about aSymboldefinition.Diagnostic: a linter error message that can be reported at a source file location.SyntacticRule: super class for all syntactic rules.SyntacticDocument: context about a single source file containing syntactic information such as trees/tokens.SemanticRule: super class for all semantic rules.SemanticDocument: context about a single source file containing syntactic information such as trees/tokens and semantic information such as symbols/types/synthetics.
Scalameta Trees
Latest Scaladoc: v4.14.1
The tree API is available through import scala.meta._. Key data structures
include:
Tree: the supertype of all tree nodes. Key methods include:pos: Position: the source code position of this tree nodesymbol: Symbol: extension method made available viaimport scalafix.v1._, requires an implicitSemanticDocument. Returns the the symbol of this tree nodesyntax: String: the pretty-printed tree nodestructure: String: the raw structure of this tree node, useful for figuring out how to pattern match against a particular tree node.
Term: the supertype for all term nodes in "term position". Terms are the parts of programs that get executed at runtime such asrun(42)inval x: String = run(42).Type: the supertype for all type nodes in "type position". Type are the parts of programs that only exist at compile time, such asStringinval x: String = "".Stat: the supertype for all tree nodes that can appear in "statement position". Statement position is theDefn: the supertype for all definitions
Scalameta Tokens
Latest Scaladoc: v4.14.1
The type scala.meta.Token is a representation of all lexical tokens in the
Scala language. Each token kind has it's own type, such as Token.Space, and
Token.KwClass ("keyword class").
The token API is available through import scala.meta._. Key data structures
include:
Token: the supertype for all token kinds. Sub-types ofTokenincludeToken.Space,Token.KwClass("keywordclass"),Token.LeftParenandToken.Colon.Tokens: a sequence of tokens with efficient collection operations such as slice, take and drop. It's important to keep in mind that a normal source file can have tens of thousands of tokens so operations likefiltermay perform badly.
case class User(name: String)
User("\"John")
// res0: User = User(name = "\"John")
