SaropaLintRule class abstract

Base class for Saropa lint rules with enhanced features:

  1. Hyphenated ignore comments: Supports both // ignore: no_empty_block and // ignore: no-empty-block formats (see IgnoreUtils).

  2. Context-aware suppression: Automatically skip generated files, test files, or example files by overriding the skip* getters.

  3. Documentation URLs: Auto-generates documentation links for rules.

  4. Severity overrides: Supports project-level severity configuration.

Usage:

class MyRule extends SaropaLintRule {
  const MyRule() : super(code: _code);

  static const LintCode _code = LintCode(
    name: 'my_rule_name',
    // ...
  );

  // Optional: skip generated files (default: true)
  @override
  bool get skipGeneratedCode => true;

  @override
  void runWithReporter(
    CustomLintResolver resolver,
    SaropaDiagnosticReporter reporter,
    CustomLintContext context,
  ) {
    // Use reporter.atNode() as usual
  }
}
Implementers

Constructors

SaropaLintRule({required LintCode code})

Properties

accuracyTarget → AccuracyTarget?
Optional accuracy target for this rule (for documentation and tooling). Does not enforce; used by reports and rule-audit scripts.
no setter
applicableFileTypes → Set<FileType>?
The file types this rule applies to.
no setter
canUseParsedResult → bool
Indicates whether this analysis rule can work with just the parsed information or if it requires a resolved unit.
no setterinherited
certIds → List<String>
CERT coding standard identifiers (e.g. STR02-C). Populate only where there is a clear mapping; leave empty for most rules initially.
no setter
code → LintCode
The lint code for this rule.
no setter
configAliases → List<String>
Alternate config keys that can be used to reference this rule.
no setter
conflictingRules → List<String>
Curated opposite/competing rule names.
no setter
cost → RuleCost
The estimated execution cost of this rule.
no setter
cweIds → List<int>
CWE identifiers this rule helps prevent or detect. https://cwe.mitre.org/ — e.g. CWE-798 (Hardcoded Credentials).
no setter
description → String
Short description suitable for display in console output and IDEs.
finalinherited
diagnosticCode → DiagnosticCode
The code to report for a violation.
no setter
diagnosticCodes → List<DiagnosticCode>
The diagnostic codes associated with this analysis rule.
no setterinherited
documentationUrl → String
Returns the documentation URL for this rule.
no setter
effectiveSeverity → DiagnosticSeverity?
Get the effective severity for this rule, considering overrides.
no setter
exampleBad → String?
Short code example that VIOLATES this rule (shown in CLI walkthrough).
no setter
exampleGood → String?
Short code example of COMPLIANT code (shown in CLI walkthrough).
no setter
fixGenerators → List<SaropaFixGenerator>
Fix producer generators for this rule.
no setter
hashCode → int
The hash code for this object.
no setterinherited
hyphenatedName → String
Returns the rule name in hyphenated format for display.
no setter
impact → LintImpact
The business impact of this rule's violations.
no setter
incompatibleRules → List<String>
A list of incompatible rule names.
no setterinherited
isDisabled → bool
Check if this rule is disabled via configuration.
no setter
maximumLineCount → int
Maximum line count for this rule to run.
no setter
minimumLineCount → int
Minimum line count for this rule to run.
no setter
name → String
The rule name.
finalinherited
owasp → OwaspMapping?
OWASP categories this rule helps prevent.
no setter
pubspecVisitor → PubspecVisitor?
A visitor that visits a Pubspec to perform analysis.
no setterinherited
relatedRules → List<String>
Curated "see also" rule names for discoverability in docs/IDE tooling.
no setter
reporter ← DiagnosticReporter
Sets the DiagnosticReporter for the CompilationUnit currently being visited.
no getterinherited
requiredPatterns → Set<String>?
String patterns that must be present in the file for this rule to run.
no setter
requiresAsync → bool
Whether this rule only applies to async code.
no setter
requiresBlocImport → bool
Whether this rule only applies to files that import Bloc.
no setter
requiresClassDeclaration → bool
Whether this rule only applies to files with class declarations.
no setter
requiresFlutterImport → bool
Whether this rule only applies to files that import Flutter.
no setter
requiresImports → bool
Whether this rule only applies to files with imports.
no setter
requiresMainFunction → bool
Whether this rule only applies to files with a main() function.
no setter
requiresProviderImport → bool
Whether this rule only applies to files that import Provider.
no setter
requiresRiverpodImport → bool
Whether this rule only applies to files that import Riverpod.
no setter
requiresWidgets → bool
Whether this rule only applies to Flutter widget code.
no setter
ruleStatus → RuleStatus
Lifecycle status. Default RuleStatus.ready. Use RuleStatus.beta for new or heuristic-heavy rules; RuleStatus.deprecated for sunset.
no setter
ruleType → RuleType?
Semantic type of this rule. Default null = unspecified (legacy). When set, used for quality gates, accuracy targets, and reporting.
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
skipExampleFiles → bool
Whether to skip example files (example/**).
no setter
skipFixtureFiles → bool
Whether to skip fixture files (fixture/, fixtures/).
no setter
skipGeneratedCode → bool
Whether to skip generated files (*.g.dart, *.freezed.dart, *.gen.dart).
no setter
skipTestFiles → bool
Whether to skip test files (*_test.dart, test/**).
no setter
state → RuleState
The state of this analysis rule.
finalinherited
supersedesRules → List<String>
Rule names this rule supersedes/replaces.
no setter
tags → Set<String>
Tags for filtering and discovery (e.g. in docs, IDE, or CI). Examples: 'performance', 'accessibility', 'suspicious', 'convention'.
no setter
testRelevance → TestRelevance
How this rule relates to test files.
no setter
usesTypeResolution → bool
Whether this rule triggers lazy cross-library type resolution in the analyzer (e.g. .staticType, .library, .allSupertypes, .enclosingElement).
no setter

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
registerNodeProcessors(RuleVisitorRegistry registry, RuleContext context) → void
Registers node processors in the given registry.
reportAtNode(AstNode? node, {List<Object> arguments = const [], List<DiagnosticMessage>? contextMessages}) → Diagnostic?
Reports a diagnostic at node with message arguments and contextMessages.
inherited
reportAtOffset(int offset, int length, {List<Object> arguments = const [], List<DiagnosticMessage>? contextMessages}) → Diagnostic
Reports a diagnostic at offset, with length, with message arguments and contextMessages.
inherited
reportAtPubNode(PubspecNode node, {List<Object> arguments = const [], List<DiagnosticMessage> contextMessages = const []}) → Diagnostic
Reports a diagnostic at Pubspec node, with message arguments and contextMessages.
inherited
reportAtSourceRange(SourceRange sourceRange, {List<Object> arguments = const [], List<DiagnosticMessage>? contextMessages}) → Diagnostic
Reports a diagnostic at sourceRange, with message arguments and contextMessages.
inherited
reportAtToken(Token token, {List<Object> arguments = const [], List<DiagnosticMessage>? contextMessages}) → Diagnostic?
Reports a diagnostic at token, with message arguments and contextMessages.
inherited
runWithReporter(SaropaDiagnosticReporter reporter, SaropaContext context) → void
Override this method to implement your lint rule.
shouldSkipFile(String path) → bool
Check if a file path should be skipped based on context settings.
toString() → String
A string representation of this object.
inherited

Operators

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

Static Properties

disabledRules ↔ Set<String>?
Rules that are completely disabled via severity overrides.
getter/setter pair
enabledRules ↔ Set<String>?
Rules explicitly enabled via diagnostics config or severity overrides.
getter/setter pair
isAnalysisServer ↔ bool
True only inside the interactive analysis-server process. Armed once by SaropaLintsPlugin.start (lib/main.dart), which no bin/ CLI runs.
getter/setter pair
severityOverrides ↔ Map<String, DiagnosticSeverity>?
Global severity overrides map.
getter/setter pair

Static Methods

deferForRapidEdit(String path, int unitId) → bool
Whether ALL saropa_lints rules should be deferred for path on the current analysis pass (unitId) because the file is being rapidly edited (in flux).
isExamplePath(String normalizedPath) → bool
Single source of truth for whether a normalized (forward-slash) path sits inside an example directory. Handles both absolute paths (/project/example/lib/foo.dart) and relative paths (example/lib/foo.dart). Covers example/, examples/, and example_packages/ — the three conventional locations for fixture and sample code.

Constants

documentationBaseUrl → const String
Base URL for rule documentation.