StyleRule class abstract

Base class for all style rules.

Implement this class to create custom rules that analyze Dart AST and report violations.

Example:

class AvoidPrintRule extends StyleRule {
  @override
  String get id => 'avoid-print';

  @override
  String get description => 'Avoid using print in production code.';

  @override
  RuleSeverity get defaultSeverity => RuleSeverity.warning;

  @override
  RuleCategory get category => RuleCategory.quality;

  @override
  List<Violation> check(CompilationUnit unit, {LineInfo? lineInfo}) {
    // Analyze AST and return violations
  }
}
Implementers

Constructors

StyleRule()

Properties

category → RuleCategory
Category this rule belongs to.
no setter
defaultSeverity → RuleSeverity
Default severity for violations of this rule.
no setter
description → String
Human-readable description of what this rule checks.
no setter
documentationUrl → String?
Documentation URL for this rule.
no setter
hashCode → int
The hash code for this object.
no setterinherited
id → String
Unique identifier for this rule (e.g., 'avoid-dynamic').
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

check(CompilationUnit unit, {LineInfo? lineInfo}) → List<Violation>
Check the compilation unit for violations.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited