Skip to main content

slopguard_core/
finding.rs

1use std::path::PathBuf;
2
3use serde::{Deserialize, Serialize};
4
5use crate::rule::{Category, RuleId, Severity};
6
7/// A single finding from scanning a source file.
8#[derive(Debug, Clone, Serialize, Deserialize)]
9pub struct Finding {
10    pub rule_id: RuleId,
11    pub severity: Severity,
12    pub category: Category,
13    pub message: String,
14    #[serde(skip_serializing_if = "Option::is_none")]
15    pub note: Option<String>,
16    #[serde(skip_serializing_if = "Option::is_none")]
17    pub fix: Option<String>,
18    pub file: PathBuf,
19    pub line: usize,
20    pub column: usize,
21    pub end_line: usize,
22    pub end_column: usize,
23    pub matched_text: String,
24    /// LLM confidence in `[0.0, 1.0]` for findings confirmed by an AI rule.
25    /// `None` for pure AST findings. Serialized in JSON/SARIF only; the text
26    /// output ignores it.
27    #[serde(default, skip_serializing_if = "Option::is_none")]
28    pub confidence: Option<f64>,
29}
30
31/// Aggregate statistics from a scan run.
32#[derive(Debug, Clone, Serialize, Deserialize)]
33pub struct ScanStats {
34    pub errors: usize,
35    pub warnings: usize,
36    pub total: usize,
37    pub files_scanned: usize,
38}
39
40/// Cache statistics for a scan run.
41#[derive(Debug, Clone, Default, Serialize, Deserialize)]
42pub struct CacheStats {
43    pub cached: usize,
44    pub changed: usize,
45}
46
47/// The result of scanning one or more paths.
48#[derive(Debug, Clone, Serialize, Deserialize)]
49pub struct ScanResult {
50    pub findings: Vec<Finding>,
51    pub stats: ScanStats,
52    #[serde(default)]
53    pub cache_stats: Option<CacheStats>,
54}