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