guardy 0.2.4

Fast, secure git hooks in Rust with secret scanning and protected file synchronization
Documentation
use std::{path::PathBuf, sync::Arc};

use super::static_data::patterns::CompiledPattern;

/// Represents a detected secret match in a file
#[derive(Debug, Clone)]
pub struct SecretMatch {
    pub file_path: Arc<PathBuf>, // Shared across all matches in the same file
    pub line_number: usize,
    pub line_content: String,
    pub matched_text: String,
    pub start_pos: usize,
    pub end_pos: usize,
    pub pattern: Arc<CompiledPattern>, // Contains name, description, entropy_threshold, etc.
    pub entropy: f64,                  // Entropy score
}

/// Statistics from a scanning operation
#[derive(Debug, Default)]
pub struct ScanStats {
    pub files_scanned: usize,
    pub files_skipped: usize,
    pub processing_errors: usize,
    pub total_matches: usize,
    pub scan_duration_ms: u64,
}

// Dead code removed:
// - Warning: Replaced by direct tracing::warn!() logging
// - ScanFileResult: No longer needed with streaming output
// - ScanResult: Simplified to just return ScanStats

/// Scanning mode for determining parallelization strategy
#[derive(
    Debug, Clone, Copy, PartialEq, clap::ValueEnum, serde::Serialize, serde::Deserialize, Default,
)]
pub enum ScanMode {
    /// Always use sequential processing
    Sequential,
    /// Always use parallel processing
    Parallel,
    /// Automatically choose based on file count (smart default)
    #[default]
    Auto,
}

// ScannerConfig removed - use config::core::ScannerConfig directly from GUARDY_CONFIG
// This eliminates duplication and ensures single source of truth

/// Main scanner struct - handles secret detection across files and directories
///
/// All configuration is accessed directly from GUARDY_CONFIG for simplicity and efficiency.
/// Filters are cached for performance (created once, reused everywhere).
#[derive(Clone)]
pub struct Scanner {
    /// Cached filters for performance (created once, reused everywhere)
    pub(crate) binary_filter: std::sync::Arc<super::filters::directory::BinaryFilter>,
    pub(crate) path_filter: std::sync::Arc<super::filters::directory::PathFilter>,
    pub(crate) size_filter: std::sync::Arc<super::filters::directory::SizeFilter>,
    /// Content filters for secret detection optimization
    pub(crate) prefilter: std::sync::Arc<super::filters::content::ContextPrefilter>,
    pub(crate) regex_executor: std::sync::Arc<super::filters::content::RegexExecutor>,
    pub(crate) comment_filter: std::sync::Arc<super::filters::content::CommentFilter>,
}