code_baseline/rules/
mod.rs1pub mod ast;
2pub mod banned_dependency;
3pub mod banned_import;
4pub mod banned_pattern;
5pub mod factory;
6pub mod file_presence;
7pub mod ratchet;
8pub mod required_pattern;
9pub mod tailwind_dark_mode;
10pub mod tailwind_theme_tokens;
11pub mod window_pattern;
12
13use crate::config::Severity;
14use std::path::{Path, PathBuf};
15
16pub trait Rule: Send + Sync {
18 fn id(&self) -> &str;
20
21 fn severity(&self) -> Severity;
23
24 fn file_glob(&self) -> Option<&str>;
26
27 fn check_file(&self, ctx: &ScanContext) -> Vec<Violation>;
29}
30
31pub struct ScanContext<'a> {
33 pub file_path: &'a Path,
34 pub content: &'a str,
35}
36
37#[derive(Debug, Clone)]
39pub struct Fix {
40 pub old: String,
41 pub new: String,
42}
43
44#[derive(Debug, Clone)]
46pub struct Violation {
47 pub rule_id: String,
48 pub severity: Severity,
49 pub file: PathBuf,
50 pub line: Option<usize>,
51 pub column: Option<usize>,
52 pub message: String,
53 pub suggest: Option<String>,
54 pub source_line: Option<String>,
55 pub fix: Option<Fix>,
56}
57
58#[derive(Debug)]
60pub enum RuleBuildError {
61 InvalidRegex(String, regex::Error),
62 MissingField(String, &'static str),
63}
64
65impl std::fmt::Display for RuleBuildError {
66 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
67 match self {
68 RuleBuildError::InvalidRegex(id, err) => {
69 write!(f, "rule '{}': invalid regex: {}", id, err)
70 }
71 RuleBuildError::MissingField(id, field) => {
72 write!(f, "rule '{}': missing required field '{}'", id, field)
73 }
74 }
75 }
76}
77
78impl std::error::Error for RuleBuildError {}