ferrous_forge/validation/violation.rs
1//! Violation types and reporting
2
3use serde::{Deserialize, Serialize};
4use std::path::PathBuf;
5
6/// Types of violations that can be detected
7#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub enum ViolationType {
9 /// Underscore parameter or let assignment bandaid
10 UnderscoreBandaid,
11 /// Wrong Rust edition (locked by project config)
12 WrongEdition,
13 /// File exceeds size limit
14 FileTooLarge,
15 /// Function exceeds size limit
16 FunctionTooLarge,
17 /// Line exceeds length limit
18 LineTooLong,
19 /// Use of .unwrap() or .expect() in production code
20 UnwrapInProduction,
21 /// Missing documentation
22 MissingDocs,
23 /// Missing required dependencies
24 MissingDependencies,
25 /// Rust version too old (locked by project config)
26 OldRustVersion,
27 /// A project configuration value is locked and was violated
28 LockedSetting,
29 /// Module-level //! documentation is missing
30 MissingModuleDoc,
31 /// Cargo.toml is missing [lints.rustdoc] configuration
32 MissingDocConfig,
33}
34
35/// Severity level of a violation
36#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
37pub enum Severity {
38 /// Violation that prevents code from compiling
39 Error,
40 /// Violation that should be fixed but doesn't break compilation
41 Warning,
42}
43
44/// A single standards violation
45#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
46pub struct Violation {
47 /// Type of violation
48 pub violation_type: ViolationType,
49 /// File where violation occurred
50 pub file: PathBuf,
51 /// Line number (1-based for display)
52 pub line: usize,
53 /// Human-readable message
54 pub message: String,
55 /// Severity of the violation
56 pub severity: Severity,
57}
58
59impl Violation {
60 /// Create a new violation
61 pub fn new(
62 violation_type: ViolationType,
63 file: PathBuf,
64 line: usize,
65 message: String,
66 severity: Severity,
67 ) -> Self {
68 Self {
69 violation_type,
70 file,
71 line,
72 message,
73 severity,
74 }
75 }
76
77 /// Returns true if this violation represents a locked setting (edition/version/config lock)
78 pub fn is_locked_setting(&self) -> bool {
79 matches!(
80 self.violation_type,
81 ViolationType::WrongEdition
82 | ViolationType::OldRustVersion
83 | ViolationType::LockedSetting
84 )
85 }
86}