use std::path::PathBuf;
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Violation {
pub file: PathBuf,
pub line: usize,
pub rule: &'static str,
pub message: String,
}
pub fn rendered(violation: &Violation) -> String {
format!(
"{}:{}: {} — {}",
violation.file.display(),
violation.line,
violation.rule,
violation.message
)
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn a_violation_renders_its_file_line_rule_and_message() {
let rendering = rendered(&Violation {
file: PathBuf::from("src/widget.rs"),
line: 12,
rule: "no-monkeypatch",
message: "patches `os.environ`".to_string(),
});
assert_eq!(
rendering,
"src/widget.rs:12: no-monkeypatch — patches `os.environ`"
);
}
}