abstract class Rule extends AnyRef

A Scalafix Rule.

To provide automatic fixes for this rule, override the fix method. Example:

object ReverseNames extends Rule("ReverseNames") {
  override def fix(ctx: RuleCtx) =
    ctx.tree.collect {
      case name @ Name(value) => ctx.replaceTree(name, value.reverse)
    }.asPatch
}

To report violations of this rule (without automatic fix), override the check method. Example:

// example syntactic linter
object NoNulls extends Rule("NoNulls") {
  val error = LintCategory.error("Nulls are not allowed.")
  override def check(ctx: RuleCtx): List[Diagnostic] = ctx.tree.collect {
    case nil @ q"null" => error.at(nil.pos)
  }
}
Self Type
Rule
Annotations
@deprecated
Deprecated

(Since version 0.9.28) Use scalafix.v1.Rule instead

Linear Supertypes
Known Subclasses
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Rule
  2. AnyRef
  3. Any
Implicitly
  1. by any2stringadd
  2. by StringFormat
  3. by Ensuring
  4. by ArrowAssoc
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Rule(ruleName: v0.RuleName)

    ruleName

    Name of this rule that users call via .scalafix.conf or in the sbt shell. By convention, a name should be PascalCase matching the class name of the rule. Example good name: NoVars, ExplicitUnit. Example bad name: no-vars, noVars, FixVars.

Value Members

  1. final def apply(ctx: RuleCtx, patches: Map[v0.RuleName, v0.Patch]): String
  2. final def apply(ctx: RuleCtx, patch: v0.Patch): String
  3. final def apply(input: String): String
  4. final def apply(input: scala.meta.Input, config: ScalafixConfig = ScalafixConfig.default): String
  5. final def apply(ctx: RuleCtx): String

    Returns string output of applying this single patch.

  6. final def applyAndLint(ctx: RuleCtx): (String, List[RuleDiagnostic])
  7. def check(ctx: RuleCtx): Seq[v0.Diagnostic]

    Returns linter messages to report violations of this rule.

  8. def description: String

    A single sentence summary of what this rule does.

  9. final def diff(ctx: RuleCtx): String

    Returns unified diff from applying this patch

  10. def fix(ctx: RuleCtx): v0.Patch

    Returns a patch to fix violations of this rule.

  11. def init(config: Conf): Configured[Rule]

    Initialize this rule with the given user configuration.

    Initialize this rule with the given user configuration.

    This method is called once by scalafix before rule is called. Use this method to either read custom configuration or to build expensive indices.

    config

    The .scalafix.conf configuration.

    returns

    the initialized rule or an error. If no initialization is needed, return Configured.Ok(this).

  12. final def merge(other: Rule): Rule

    Combine this rule with another rule.

  13. final def name: v0.RuleName
  14. final def toString(): String
    Definition Classes
    Rule → AnyRef → Any