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
- Alphabetic
- By Inheritance
- Rule
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Instance Constructors
-
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
-
final
def
!=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
final
def
##(): Int
- Definition Classes
- AnyRef → Any
- def +(other: String): String
- def ->[B](y: B): (Rule, B)
-
final
def
==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
- final def apply(ctx: RuleCtx, patches: Map[v0.RuleName, v0.Patch]): String
- final def apply(ctx: RuleCtx, patch: v0.Patch): String
- final def apply(input: String): String
- final def apply(input: scala.meta.Input, config: ScalafixConfig = ScalafixConfig.default): String
-
final
def
apply(ctx: RuleCtx): String
Returns string output of applying this single patch.
- final def applyAndLint(ctx: RuleCtx): (String, List[RuleDiagnostic])
-
final
def
asInstanceOf[T0]: T0
- Definition Classes
- Any
-
def
check(ctx: RuleCtx): Seq[v0.Diagnostic]
Returns linter messages to report violations of this rule.
-
def
clone(): AnyRef
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
-
def
description: String
A single sentence summary of what this rule does.
-
final
def
diff(ctx: RuleCtx, patch: v0.Patch): String
- Attributes
- protected
-
final
def
diff(ctx: RuleCtx): String
Returns unified diff from applying this patch
- def ensuring(cond: (Rule) ⇒ Boolean, msg: ⇒ Any): Rule
- def ensuring(cond: (Rule) ⇒ Boolean): Rule
- def ensuring(cond: Boolean, msg: ⇒ Any): Rule
- def ensuring(cond: Boolean): Rule
-
final
def
eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
def
equals(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
-
def
finalize(): Unit
- Attributes
- protected[lang]
- Definition Classes
- AnyRef
- Annotations
- @throws( classOf[java.lang.Throwable] )
-
def
fix(ctx: RuleCtx): v0.Patch
Returns a patch to fix violations of this rule.
-
def
fixWithName(ctx: RuleCtx): Map[v0.RuleName, v0.Patch]
- Attributes
- protected[scalafix]
-
final
def
getClass(): Class[_]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
def
hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
-
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).
-
final
def
isInstanceOf[T0]: Boolean
- Definition Classes
- Any
-
final
def
merge(other: Rule): Rule
Combine this rule with another rule.
- final def name: v0.RuleName
-
final
def
ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
-
final
def
notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
final
def
notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
-
def
semanticOption: Option[SemanticdbIndex]
- Attributes
- protected[scalafix]
-
final
def
synchronized[T0](arg0: ⇒ T0): T0
- Definition Classes
- AnyRef
-
final
def
toString(): String
- Definition Classes
- Rule → AnyRef → Any
-
final
def
wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... )
-
final
def
wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws( ... ) @native()
- def →[B](y: B): (Rule, B)
Deprecated Value Members
-
def
formatted(fmtstr: String): String
- Implicit
- This member is added by an implicit conversion from Rule to StringFormat[Rule] performed by method StringFormat in scala.Predef.
- Definition Classes
- StringFormat
- Annotations
- @deprecated @inline()
- Deprecated
(Since version 2.12.16) Use
formatString.format(value)
instead ofvalue.formatted(formatString)
, or use thef""
string interpolator. In Java 15 and later,formatted
resolves to the new method in String which has reversed parameters.