code_baseline/config.rs
1/// Severity level for a rule violation.
2#[derive(Debug, Clone, Copy, PartialEq, Eq)]
3pub enum Severity {
4 Error,
5 Warning,
6}
7
8/// Parsed rule configuration from `baseline.toml`.
9#[derive(Debug, Clone)]
10pub struct RuleConfig {
11 pub id: String,
12 pub severity: Severity,
13 pub message: String,
14 pub suggest: Option<String>,
15 pub glob: Option<String>,
16 /// Classes exempt from enforcement.
17 pub allowed_classes: Vec<String>,
18 /// User-provided token mappings (`"raw-class=semantic-class"`).
19 pub token_map: Vec<String>,
20 /// Literal pattern to search for (used by ratchet and banned-pattern rules).
21 pub pattern: Option<String>,
22 /// Maximum allowed occurrences (used by ratchet rules).
23 pub max_count: Option<usize>,
24 /// Banned package names (used by banned-import and banned-dependency rules).
25 pub packages: Vec<String>,
26 /// Whether `pattern` should be interpreted as a regex (default: false).
27 pub regex: bool,
28 /// Manifest filename to check (used by banned-dependency, defaults to `package.json`).
29 pub manifest: Option<String>,
30 /// Glob patterns for files to exclude from this rule.
31 pub exclude_glob: Vec<String>,
32 /// Only run rule if file contains this string.
33 pub file_contains: Option<String>,
34 /// Only run rule if file does NOT contain this string.
35 pub file_not_contains: Option<String>,
36 /// Required files that must exist (used by file-presence rule).
37 pub required_files: Vec<String>,
38 /// Forbidden files that must NOT exist (used by file-presence rule).
39 pub forbidden_files: Vec<String>,
40 /// Condition pattern: only enforce required-pattern if this pattern is present.
41 pub condition_pattern: Option<String>,
42}
43
44impl Default for RuleConfig {
45 fn default() -> Self {
46 Self {
47 id: String::new(),
48 severity: Severity::Warning,
49 message: String::new(),
50 suggest: None,
51 glob: None,
52 allowed_classes: Vec::new(),
53 token_map: Vec::new(),
54 pattern: None,
55 max_count: None,
56 packages: Vec::new(),
57 regex: false,
58 manifest: None,
59 exclude_glob: Vec::new(),
60 file_contains: None,
61 file_not_contains: None,
62 required_files: Vec::new(),
63 forbidden_files: Vec::new(),
64 condition_pattern: None,
65 }
66 }
67}