Scalafix

Scalafix

  • User guide
  • Developer guide
  • Browse sources
  • GitHub

›API Reference

Implementing rules

  • Setup
  • Before you write code
  • Tutorial
  • Local rules

API Reference

  • Overview
  • Patch
  • SymbolMatcher
  • SymbolInformation
  • SemanticType
  • SemanticTree

Contributing

  • Guide
Edit

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.2

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 .apply and for-comprehensions.
  • Symbol: a unique identifier for a definition. For example, the String class has the symbol java/lang/String#. The type alias to String in the Scala standard library has the symbol scala/Predef.String#.
  • SymbolInformation: a data structure containing metadata about a Symbol definition.
  • 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.13.5

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 node
    • symbol: Symbol: extension method made available via import scalafix.v1._, requires an implicit SemanticDocument. Returns the the symbol of this tree node
    • syntax: String: the pretty-printed tree node
    • structure: 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 as run(42) in val 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 as String in val x: String = "".
  • Stat: the supertype for all tree nodes that can appear in "statement position". Statement position is the
  • Defn: the supertype for all definitions

Scalameta Tokens

Latest Scaladoc: v4.13.5

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 of Token include Token.Space, Token.KwClass ("keyword class"), Token.LeftParen and Token.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 like filter may perform badly.
case class User(name: String)
User("\"John")
// res0: User = User(name = "\"John")
← Local rulesPatch →
  • Compatibility considerations
  • Packages
    • Scalafix v1
    • Scalameta Trees
    • Scalameta Tokens
Scalafix
Docs
Get startedRulesExtend Scalafix
Community
Chat on DiscordDiscuss on Scala Users
More
GitHub
Copyright © 2025 Scala Center