use std::path::Path;
use crate::analyzer::CodeIssue;
pub trait GenericRule: Send + Sync {
fn name(&self) -> &'static str;
fn check_content(&self, file_path: &Path, content: &str, lang: &str) -> Vec<CodeIssue>;
}
pub struct GenericRuleEngine {
rules: Vec<Box<dyn GenericRule>>,
}
impl Default for GenericRuleEngine {
fn default() -> Self {
Self::new()
}
}
impl GenericRuleEngine {
pub fn new() -> Self {
Self { rules: Vec::new() }
}
pub fn check_file(&self, file_path: &Path, content: &str, lang: &str) -> Vec<CodeIssue> {
let mut issues = Vec::new();
for rule in &self.rules {
issues.extend(rule.check_content(file_path, content, lang));
}
issues
}
pub fn rule_names(&self) -> Vec<&'static str> {
self.rules.iter().map(|r| r.name()).collect()
}
}