garbage_code_hunter/rules/
generic.rs1use std::path::Path;
2
3use crate::analyzer::CodeIssue;
4
5pub trait GenericRule: Send + Sync {
9 fn name(&self) -> &'static str;
11
12 fn check_content(&self, file_path: &Path, content: &str, lang: &str) -> Vec<CodeIssue>;
14}
15
16pub struct GenericRuleEngine {
18 rules: Vec<Box<dyn GenericRule>>,
19}
20
21impl Default for GenericRuleEngine {
22 fn default() -> Self {
23 Self::new()
24 }
25}
26
27impl GenericRuleEngine {
28 pub fn new() -> Self {
29 Self { rules: Vec::new() }
30 }
31
32 pub fn check_file(&self, file_path: &Path, content: &str, lang: &str) -> Vec<CodeIssue> {
33 let mut issues = Vec::new();
34 for rule in &self.rules {
35 issues.extend(rule.check_content(file_path, content, lang));
36 }
37 issues
38 }
39
40 pub fn rule_names(&self) -> Vec<&'static str> {
41 self.rules.iter().map(|r| r.name()).collect()
42 }
43}