Skip to main content

TreeSitterRule

Trait TreeSitterRule 

Source
pub trait TreeSitterRule: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn supported_languages(&self) -> &'static [Language];
    fn check(&self, file: &ParsedFile) -> Vec<CodeIssue>;

    // Provided methods
    fn skips_test_files(&self) -> bool { ... }
    fn check_with_context(
        &self,
        file: &ParsedFile,
        _is_test_file: bool,
        _context: &FileContext,
        _config: &ProjectConfig,
    ) -> Vec<CodeIssue> { ... }
}
Expand description

A code quality rule that analyzes source files using tree-sitter AST.

Unlike the original [crate::rules::Rule] trait which requires syn::File, this trait works on tree-sitter’s language-agnostic CST. Rules declare which languages they support via supported_languages.

Required Methods§

Source

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

Unique identifier for this rule (e.g. "deep-nesting").

Source

fn supported_languages(&self) -> &'static [Language]

Languages supported by this rule.

Source

fn check(&self, file: &ParsedFile) -> Vec<CodeIssue>

Analyze a parsed file and return detected issues.

Provided Methods§

Source

fn skips_test_files(&self) -> bool

Whether to skip test files (default: true).

Source

fn check_with_context( &self, file: &ParsedFile, _is_test_file: bool, _context: &FileContext, _config: &ProjectConfig, ) -> Vec<CodeIssue>

Analyze a file with additional context about the file’s role in the project. Override this when the rule needs to adjust behavior based on file context (e.g. skipping UI files, relaxing thresholds for examples) or config.

Implementors§