Skip to main content

cac_core/
violation.rs

1use crate::policy::PolicySeverity;
2use serde::{Deserialize, Serialize};
3
4#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
5pub struct Violation {
6    pub rule_id: String,
7    pub policy_id: String,
8    pub policy_name: String,
9    pub framework: String,
10    pub severity: PolicySeverity,
11    pub file_path: String,
12    pub line: u32,
13    pub column: u32,
14    pub snippet: String,
15    pub message: String,
16    pub auto_fixable: bool,
17}
18
19#[derive(Debug, Clone, Serialize, Deserialize)]
20pub struct ScanReport {
21    pub scanned_at: String,
22    pub root: String,
23    pub files_scanned: usize,
24    pub violations: Vec<Violation>,
25}
26
27impl ScanReport {
28    pub fn violation_count(&self) -> usize {
29        self.violations.len()
30    }
31
32    pub fn has_critical(&self) -> bool {
33        self.violations
34            .iter()
35            .any(|v| v.severity == PolicySeverity::Critical)
36    }
37}
38
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct FixProposal {
41    pub violation_id: String,
42    pub file_path: String,
43    pub original_snippet: String,
44    pub fixed_snippet: String,
45    pub description: String,
46}
47
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct ValidationReport {
50    pub validated_at: String,
51    pub original_violations: usize,
52    pub remaining_violations: usize,
53    pub fixes_applied: usize,
54    pub passed: bool,
55    pub adversarial_notes: Vec<String>,
56    pub remaining: Vec<Violation>,
57}