cc_audit/config/severity.rs
1//! Rule severity configuration.
2
3use crate::rules::RuleSeverity;
4use serde::{Deserialize, Serialize};
5use std::collections::HashSet;
6
7/// Rule severity configuration - controls how findings affect CI exit code.
8///
9/// Priority: ignore > warn > default
10///
11/// Example:
12/// ```yaml
13/// severity:
14/// default: error # All rules are errors by default
15/// warn:
16/// - PI-001 # Treat as warning only
17/// - PI-002
18/// ignore:
19/// - OP-001 # Completely ignore
20/// ```
21#[derive(Debug, Clone, Serialize, Deserialize)]
22#[serde(default)]
23pub struct SeverityConfig {
24 /// Default severity for all rules (error by default).
25 pub default: RuleSeverity,
26 /// Rule IDs to treat as warnings (report only, exit 0).
27 #[serde(default)]
28 pub warn: HashSet<String>,
29 /// Rule IDs to ignore completely (no report).
30 /// Note: These are merged with disabled_rules.
31 #[serde(default)]
32 pub ignore: HashSet<String>,
33}
34
35impl Default for SeverityConfig {
36 fn default() -> Self {
37 Self {
38 default: RuleSeverity::Error,
39 warn: HashSet::new(),
40 ignore: HashSet::new(),
41 }
42 }
43}
44
45impl SeverityConfig {
46 /// Get the effective RuleSeverity for a rule ID.
47 /// Returns None if the rule should be ignored.
48 pub fn get_rule_severity(&self, rule_id: &str) -> Option<RuleSeverity> {
49 // Priority: ignore > warn > default
50 if self.ignore.contains(rule_id) {
51 return None; // Ignore this rule
52 }
53 if self.warn.contains(rule_id) {
54 return Some(RuleSeverity::Warn);
55 }
56 Some(self.default)
57 }
58}