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 (not 2024)
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
26 OldRustVersion,
27}
28
29/// Severity level of a violation
30#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
31pub enum Severity {
32 /// Violation that prevents code from compiling
33 Error,
34 /// Violation that should be fixed but doesn't break compilation
35 Warning,
36}
37
38/// A single standards violation
39#[derive(Debug, Clone, Serialize, Deserialize)]
40pub struct Violation {
41 /// Type of violation
42 pub violation_type: ViolationType,
43 /// File where violation occurred
44 pub file: PathBuf,
45 /// Line number (1-based for display)
46 pub line: usize,
47 /// Human-readable message
48 pub message: String,
49 /// Severity of the violation
50 pub severity: Severity,
51}
52
53impl Violation {
54 /// Create a new violation
55 pub fn new(
56 violation_type: ViolationType,
57 file: PathBuf,
58 line: usize,
59 message: String,
60 severity: Severity,
61 ) -> Self {
62 Self {
63 violation_type,
64 file,
65 line,
66 message,
67 severity,
68 }
69 }
70}