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

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 !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. def +(other: String): String
    Implicit
    This member is added by an implicit conversion from Rule toany2stringadd[Rule] performed by method any2stringadd in scala.Predef.
    Definition Classes
    any2stringadd
  4. def ->[B](y: B): (Rule, B)
    Implicit
    This member is added by an implicit conversion from Rule toArrowAssoc[Rule] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @inline()
  5. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  6. final def apply(ctx: RuleCtx, patches: Map[v0.RuleName, v0.Patch]): String
  7. final def apply(ctx: RuleCtx, patch: v0.Patch): String
  8. final def apply(input: String): String
  9. final def apply(input: scala.meta.Input, config: ScalafixConfig = ScalafixConfig.default): String
  10. final def apply(ctx: RuleCtx): String

    Returns string output of applying this single patch.

  11. final def applyAndLint(ctx: RuleCtx): (String, List[RuleDiagnostic])
  12. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  13. def check(ctx: RuleCtx): Seq[v0.Diagnostic]

    Returns linter messages to report violations of this rule.

  14. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native()
  15. def description: String

    A single sentence summary of what this rule does.

  16. final def diff(ctx: RuleCtx, patch: v0.Patch): String
    Attributes
    protected
  17. final def diff(ctx: RuleCtx): String

    Returns unified diff from applying this patch

  18. def ensuring(cond: (Rule) => Boolean, msg: => Any): Rule
    Implicit
    This member is added by an implicit conversion from Rule toEnsuring[Rule] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  19. def ensuring(cond: (Rule) => Boolean): Rule
    Implicit
    This member is added by an implicit conversion from Rule toEnsuring[Rule] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  20. def ensuring(cond: Boolean, msg: => Any): Rule
    Implicit
    This member is added by an implicit conversion from Rule toEnsuring[Rule] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  21. def ensuring(cond: Boolean): Rule
    Implicit
    This member is added by an implicit conversion from Rule toEnsuring[Rule] performed by method Ensuring in scala.Predef.
    Definition Classes
    Ensuring
  22. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  23. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  24. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable])
  25. def fix(ctx: RuleCtx): v0.Patch

    Returns a patch to fix violations of this rule.

  26. def fixWithName(ctx: RuleCtx): Map[v0.RuleName, v0.Patch]
    Attributes
    protected[scalafix]
  27. def formatted(fmtstr: String): String
    Implicit
    This member is added by an implicit conversion from Rule toStringFormat[Rule] performed by method StringFormat in scala.Predef.
    Definition Classes
    StringFormat
    Annotations
    @inline()
  28. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  29. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native()
  30. 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).

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

    Combine this rule with another rule.

  33. final def name: v0.RuleName
  34. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  35. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  36. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native()
  37. def semanticOption: Option[SemanticdbIndex]
    Attributes
    protected[scalafix]
  38. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  39. final def toString(): String
    Definition Classes
    Rule → AnyRef → Any
  40. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  41. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  42. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()

Deprecated Value Members

  1. def [B](y: B): (Rule, B)
    Implicit
    This member is added by an implicit conversion from Rule toArrowAssoc[Rule] performed by method ArrowAssoc in scala.Predef.
    Definition Classes
    ArrowAssoc
    Annotations
    @deprecated
    Deprecated

    (Since version 2.13.0) Use -> instead. If you still wish to display it as one character, consider using a font with programming ligatures such as Fira Code.

Inherited from AnyRef

Inherited from Any

Inherited by implicit conversion any2stringadd fromRule to any2stringadd[Rule]

Inherited by implicit conversion StringFormat fromRule to StringFormat[Rule]

Inherited by implicit conversion Ensuring fromRule to Ensuring[Rule]

Inherited by implicit conversion ArrowAssoc fromRule to ArrowAssoc[Rule]

Ungrouped