pub trait LanguageAnalyzer: Send + Sync {
// Required methods
fn file_extensions(&self) -> &[&str];
fn parse_file(
&self,
path: &Path,
source: &str,
config: &AnalysisConfig,
) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>;
// Provided method
fn is_test_code(&self, unit: &CodeUnit) -> bool { ... }
}Expand description
Trait for language-specific code analysis.
Implementors provide file-extension detection and parsing logic,
allowing dupes-core to work with any language.
Test code handling: Analyzers should set CodeUnit::is_test to true
for test functions, test modules, etc. The crate::analyze function will
filter them out when Config::exclude_tests is enabled, using [is_test_code].
Required Methods§
Sourcefn file_extensions(&self) -> &[&str]
fn file_extensions(&self) -> &[&str]
File extensions this analyzer handles (without the leading dot).
Sourcefn parse_file(
&self,
path: &Path,
source: &str,
config: &AnalysisConfig,
) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>
fn parse_file( &self, path: &Path, source: &str, config: &AnalysisConfig, ) -> Result<Vec<CodeUnit>, Box<dyn Error + Send + Sync>>
Parse a single source file into code units.
path is the file’s location (for diagnostics), source is the file content,
and config carries min-node / min-line thresholds.
Analyzers should tag test code via CodeUnit::is_test rather than
filtering it out; the caller handles exclusion.
Provided Methods§
Sourcefn is_test_code(&self, unit: &CodeUnit) -> bool
fn is_test_code(&self, unit: &CodeUnit) -> bool
Check whether a code unit represents test code.
The default implementation delegates to CodeUnit::is_test,
which language analyzers set during parsing.