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}
42
43/// Cache statistics for a scan run.
44#[derive(Debug, Clone, Default, Serialize, Deserialize)]
45pub struct CacheStats {
46    pub cached: usize,
47    pub changed: usize,
48}
49
50/// The result of scanning one or more paths.
51#[derive(Debug, Clone, Serialize, Deserialize)]
52pub struct ScanResult {
53    pub findings: Vec<Finding>,
54    pub stats: ScanStats,
55    #[serde(default)]
56    pub cache_stats: Option<CacheStats>,
57}