Rule

Trait Rule 

Source
pub trait Rule: Send + Sync {
    // Required methods
    fn id(&self) -> &'static str;
    fn name(&self) -> &'static str;
    fn description(&self) -> &'static str;
    fn metadata(&self) -> RuleMetadata;
    fn check_with_ast<'a>(
        &self,
        document: &Document,
        ast: Option<&'a AstNode<'a>>,
    ) -> Result<Vec<Violation>>;

    // Provided methods
    fn check(&self, document: &Document) -> Result<Vec<Violation>> { ... }
    fn can_fix(&self) -> bool { ... }
    fn fix(&self, _content: &str, _violation: &Violation) -> Option<String> { ... }
    fn create_violation(
        &self,
        message: String,
        line: usize,
        column: usize,
        severity: Severity,
    ) -> Violation { ... }
    fn create_violation_with_fix(
        &self,
        message: String,
        line: usize,
        column: usize,
        severity: Severity,
        fix: Fix,
    ) -> Violation { ... }
}
Expand description

Trait that all linting rules must implement

Required Methods§

Source

fn id(&self) -> &'static str

Unique identifier for the rule (e.g., “MD001”)

Source

fn name(&self) -> &'static str

Human-readable name for the rule (e.g., “heading-increment”)

Source

fn description(&self) -> &'static str

Description of what the rule checks

Source

fn metadata(&self) -> RuleMetadata

Metadata about this rule’s status and properties

Source

fn check_with_ast<'a>( &self, document: &Document, ast: Option<&'a AstNode<'a>>, ) -> Result<Vec<Violation>>

Check a document for violations of this rule with optional pre-parsed AST

Provided Methods§

Source

fn check(&self, document: &Document) -> Result<Vec<Violation>>

Check a document for violations of this rule (backward compatibility)

Source

fn can_fix(&self) -> bool

Whether this rule can automatically fix violations

Source

fn fix(&self, _content: &str, _violation: &Violation) -> Option<String>

Attempt to fix a violation (if supported)

Source

fn create_violation( &self, message: String, line: usize, column: usize, severity: Severity, ) -> Violation

Create a violation for this rule

Source

fn create_violation_with_fix( &self, message: String, line: usize, column: usize, severity: Severity, fix: Fix, ) -> Violation

Create a violation with a fix for this rule

Implementors§

Source§

impl<T: AstRule> Rule for T