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[LintMessage] = ctx.tree.collect {
    case nil @ q"null" => error.at(nil.pos)
  }
}
Self Type
Rule
Linear Supertypes
Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. Rule
  2. AnyRef
  3. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. All

Instance Constructors

  1. new Rule(ruleName: 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 !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. final def apply(ctx: RuleCtx, patches: Map[RuleName, Patch]): String
  5. final def apply(ctx: RuleCtx, patch: Patch): String
  6. final def apply(input: String): String
  7. final def apply(input: scala.meta.Input, config: internal.config.ScalafixConfig = ScalafixConfig.default): String
  8. final def apply(ctx: RuleCtx): String

    Returns string output of applying this single patch.

  9. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  10. def check(ctx: RuleCtx): Seq[LintMessage]

    Returns linter messages to report violations of this rule.

  11. def clone(): AnyRef
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  12. final def diff(ctx: RuleCtx, patch: Patch): String
    Attributes
    protected
  13. final def diff(ctx: RuleCtx): String

    Returns unified diff from applying this patch

  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  16. def finalize(): Unit
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  17. def fix(ctx: RuleCtx): Patch

    Returns a patch to fix violations of this rule.

  18. def fixWithName(ctx: RuleCtx): Map[RuleName, Patch]
    Attributes
    protected[scalafix]
  19. final def getClass(): Class[_]
    Definition Classes
    AnyRef → Any
  20. def hashCode(): Int
    Definition Classes
    AnyRef → Any
  21. 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).

  22. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  23. final def merge(other: Rule): Rule

    Combine this rule with another rule.

  24. final def name: RuleName
  25. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  26. final def notify(): Unit
    Definition Classes
    AnyRef
  27. final def notifyAll(): Unit
    Definition Classes
    AnyRef
  28. def semanticOption: Option[SemanticdbIndex]
    Attributes
    protected[scalafix]
  29. final def synchronized[T0](arg0: ⇒ T0): T0
    Definition Classes
    AnyRef
  30. final def toString(): String
    Definition Classes
    Rule → AnyRef → Any
  31. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  32. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  33. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. final def andThen(other: Rule): Rule
    Annotations
    @deprecated
    Deprecated

    (Since version 0.5.0) Renamed to merge.

Inherited from AnyRef

Inherited from Any

Ungrouped