pub trait RuleLinter {
// Required methods
fn feed(&mut self, node: &Node<'_>);
fn finalize(&mut self) -> Vec<RuleViolation>;
}Expand description
SINGLE-USE CONTRACT: RuleLinter instances are designed for one-time use only.
Each RuleLinter instance should be used to analyze exactly one source document and then discarded. This eliminates the complexity of state management and cleanup:
- No reset/cleanup methods needed
- No state contamination between different documents
- Simpler, more predictable behavior
After calling analyze() on a MultiRuleLinter, the entire linter and all its
rule instances become invalid and should not be reused.
§Usage Pattern
// Correct: Create fresh linter for each document
let mut linter1 = MultiRuleLinter::new_for_document(path.clone(), config.clone(), source1);
let violations1 = linter1.analyze(); // Use once, then discard
// Create new linter for next document
let mut linter2 = MultiRuleLinter::new_for_document(path, config, source2);
let violations2 = linter2.analyze(); // Fresh linter, no contaminationRequired Methods§
Sourcefn feed(&mut self, node: &Node<'_>)
fn feed(&mut self, node: &Node<'_>)
Process a single AST node and accumulate state for violation detection.
CONTRACT: This method will be called exactly once per AST node for a single document analysis session. Rule linters have access to the document content and parsed data through their initialized Context.
Sourcefn finalize(&mut self) -> Vec<RuleViolation>
fn finalize(&mut self) -> Vec<RuleViolation>
Called after all nodes have been processed to return all violations found.
CONTRACT: This method will be called exactly once at the end of document analysis.