Skip to main content

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    /// When true, skip matches that fall inside string literals (requires `ast` feature).
43    pub skip_strings: bool,
44}
45
46impl Default for RuleConfig {
47    fn default() -> Self {
48        Self {
49            id: String::new(),
50            severity: Severity::Warning,
51            message: String::new(),
52            suggest: None,
53            glob: None,
54            allowed_classes: Vec::new(),
55            token_map: Vec::new(),
56            pattern: None,
57            max_count: None,
58            packages: Vec::new(),
59            regex: false,
60            manifest: None,
61            exclude_glob: Vec::new(),
62            file_contains: None,
63            file_not_contains: None,
64            required_files: Vec::new(),
65            forbidden_files: Vec::new(),
66            condition_pattern: None,
67            skip_strings: false,
68        }
69    }
70}