use std::fmt::Debug;
use serde::Serialize;
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize)]
pub struct Offence {
pub file: String,
pub line: usize,
pub rule: &'static str,
pub description: String,
pub correction: String,
pub subject: Option<String>,
pub expected: Option<String>,
}
impl Offence {
pub fn new(
file: &str,
line: usize,
rule: &'static str,
description: String,
correction: String,
) -> Self {
Self {
file: file.to_string(),
line,
rule,
description,
correction,
subject: None,
expected: None,
}
}
pub fn with_subject(self, subject: &str) -> Self {
Self {
subject: Some(subject.to_string()),
..self
}
}
pub fn with_expected(self, expected: &str) -> Self {
Self {
expected: Some(expected.to_string()),
..self
}
}
pub fn sort_key(&self) -> (&str, usize, &'static str) {
(&self.file, self.line, self.rule)
}
}