1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
//! Violation types for Checkstyle-rs
use crate::checkstyle::api::event::SeverityLevel;
use std::cmp::Ordering;
/// Represents a violation found by a check
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Violation {
/// Line number where the violation occurs (1-based)
pub line_no: usize,
/// Column number where the violation occurs (1-based)
pub column_no: usize,
/// Column character index
pub column_char_index: usize,
/// Token type associated with the violation
pub token_type: i32,
/// Severity level of the violation
pub severity_level: SeverityLevel,
/// Module ID that generated the violation
pub module_id: String,
/// Message key for localization
pub key: String,
/// Arguments for message formatting
pub args: Vec<String>,
/// Resource bundle name
pub bundle: String,
/// Source class/module name
pub source_name: String,
/// Custom message (overrides default from bundle)
pub custom_message: Option<String>,
}
impl Violation {
/// Create a new violation
pub fn new(
line_no: usize,
column_no: usize,
column_char_index: usize,
token_type: i32,
severity_level: SeverityLevel,
module_id: String,
key: String,
args: Vec<String>,
bundle: String,
source_name: String,
custom_message: Option<String>,
) -> Self {
Self {
line_no,
column_no,
column_char_index,
token_type,
severity_level,
module_id,
key,
args,
bundle,
source_name,
custom_message,
}
}
/// Get the formatted violation message
pub fn get_message(&self) -> String {
if let Some(ref custom) = self.custom_message {
// Simple formatting - replace {0}, {1}, etc. with args
let mut msg = custom.clone();
for (i, arg) in self.args.iter().enumerate() {
msg = msg.replace(&format!("{{{i}}}"), arg);
}
msg
} else {
// TODO: Implement proper localization
format!("{}: {}", self.key, self.args.join(", "))
}
}
}
impl PartialOrd for Violation {
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
Some(self.cmp(other))
}
}
impl Ord for Violation {
fn cmp(&self, other: &Self) -> Ordering {
match self.line_no.cmp(&other.line_no) {
Ordering::Equal => match self.column_no.cmp(&other.column_no) {
Ordering::Equal => match self.module_id.cmp(&other.module_id) {
Ordering::Equal => match self.source_name.cmp(&other.source_name) {
Ordering::Equal => self.get_message().cmp(&other.get_message()),
other => other,
},
other => other,
},
other => other,
},
other => other,
}
}
}