Class/Object

scalafix.rule

Rule

Related Docs: object Rule | package rule

Permalink

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 NoVars extends Rule("NoVars") {
  val varDefinition = LintCategory.error("varDefinition", "Var is bad!")
  override def check(ctx: RuleCtx) = ctx.tree.collect {
    case definition @ q"$_ var $_ = $_" => varDefinition.at(definition.pos)
  }
}
// example semantic linter
case class NeverInferProduct(index: SemanticdbIndex)
    extends SemanticRule(index, "NeverInferProduct")
    with Product {
  val product = SymbolMatcher.exact(Symbol("_root_.scala.Product#"))
  val inferredProduct: LintCategory =
    LintCategory.error("inferredProduct", "Don't infer Product!")
  override def check(ctx: RuleCtx) =
    ctx.index.synthetics.flatMap {
      case Synthetic(pos, text, names) =>
        names.collect {
          case ResolvedName(_, product(_), _) =>
            inferredProduct.at(pos)
        }
    }
}
Self Type
Rule
Linear Supertypes
Known Subclasses
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)

    Permalink

    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

    Permalink
    Definition Classes
    AnyRef → Any
  2. final def ##(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  4. final def apply(ctx: RuleCtx, patch: Patch): String

    Permalink
  5. final def apply(input: String): String

    Permalink
  6. final def apply(input: scala.meta.Input, config: internal.config.ScalafixConfig = ScalafixConfig.default): String

    Permalink
  7. final def apply(ctx: RuleCtx): String

    Permalink

    Returns string output of applying this single patch.

  8. final def asInstanceOf[T0]: T0

    Permalink
    Definition Classes
    Any
  9. def check(ctx: RuleCtx): Seq[LintMessage]

    Permalink

    Returns linter messages to report violations of this rule.

  10. def clone(): AnyRef

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

    Permalink
    Attributes
    protected
  12. final def diff(ctx: RuleCtx): String

    Permalink

    Returns unified diff from applying this patch

  13. final def eq(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  14. def equals(arg0: Any): Boolean

    Permalink
    Definition Classes
    AnyRef → Any
  15. def finalize(): Unit

    Permalink
    Attributes
    protected[java.lang]
    Definition Classes
    AnyRef
    Annotations
    @throws( classOf[java.lang.Throwable] )
  16. def fix(ctx: RuleCtx): Patch

    Permalink

    Returns a patch to fix violations of this rule.

  17. final def getClass(): Class[_]

    Permalink
    Definition Classes
    AnyRef → Any
  18. def hashCode(): Int

    Permalink
    Definition Classes
    AnyRef → Any
  19. def init(config: Conf): Configured[Rule]

    Permalink

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

  20. final def isInstanceOf[T0]: Boolean

    Permalink
    Definition Classes
    Any
  21. final def merge(other: Rule): Rule

    Permalink

    Combine this rule with another rule.

  22. final def name: RuleName

    Permalink
  23. final def ne(arg0: AnyRef): Boolean

    Permalink
    Definition Classes
    AnyRef
  24. final def notify(): Unit

    Permalink
    Definition Classes
    AnyRef
  25. final def notifyAll(): Unit

    Permalink
    Definition Classes
    AnyRef
  26. def semanticOption: Option[SemanticdbIndex]

    Permalink
    Attributes
    protected[scalafix]
  27. final def synchronized[T0](arg0: ⇒ T0): T0

    Permalink
    Definition Classes
    AnyRef
  28. final def toString(): String

    Permalink
    Definition Classes
    Rule → AnyRef → Any
  29. final def wait(): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  30. final def wait(arg0: Long, arg1: Int): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )
  31. final def wait(arg0: Long): Unit

    Permalink
    Definition Classes
    AnyRef
    Annotations
    @throws( ... )

Deprecated Value Members

  1. final def andThen(other: Rule): Rule

    Permalink
    Annotations
    @deprecated
    Deprecated

    (Since version 0.5.0) Renamed to merge.

Inherited from AnyRef

Inherited from Any

Ungrouped