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    /// Number of findings dropped because they were present in the baseline.
39    #[serde(default)]
40    pub baseline_filtered: usize,
41    /// The git ref the scan was diffed against in `--diff` mode ("HEAD" when
42    /// no `--base` was given). `None` for a normal full scan.
43    #[serde(default, skip_serializing_if = "Option::is_none")]
44    pub diff_base: Option<String>,
45    /// Number of changed files selected by `--diff`. `None` for a full scan.
46    #[serde(default, skip_serializing_if = "Option::is_none")]
47    pub files_changed: Option<usize>,
48}
49
50/// Cache statistics for a scan run.
51#[derive(Debug, Clone, Default, Serialize, Deserialize)]
52pub struct CacheStats {
53    pub cached: usize,
54    pub changed: usize,
55}
56
57/// The result of scanning one or more paths.
58#[derive(Debug, Clone, Serialize, Deserialize)]
59pub struct ScanResult {
60    pub findings: Vec<Finding>,
61    pub stats: ScanStats,
62    #[serde(default)]
63    pub cache_stats: Option<CacheStats>,
64}