Skip to content

Commit

Permalink
consistent strict mode violation building (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
perryqh authored Aug 28, 2024
1 parent 222c289 commit 8f8e87d
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/packs/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ pub struct ViolationIdentifier {
}
#[derive(PartialEq, Clone, Eq, Hash, Debug)]
pub struct Violation {
message: String,
pub message: String,
pub identifier: ViolationIdentifier,
}

Expand All @@ -66,7 +66,7 @@ pub(crate) trait ValidatorInterface {
pub struct CheckAllResult {
reportable_violations: HashSet<Violation>,
stale_violations: Vec<ViolationIdentifier>,
strict_mode_violations: Vec<ViolationIdentifier>,
strict_mode_violations: HashSet<Violation>,
}

impl CheckAllResult {
Expand Down Expand Up @@ -99,7 +99,8 @@ impl CheckAllResult {

if !self.strict_mode_violations.is_empty() {
for v in self.strict_mode_violations.iter() {
let error_message = build_strict_violation_message(v);
let error_message =
build_strict_violation_message(&v.identifier);
writeln!(f, "{}", error_message)?;
}
}
Expand Down Expand Up @@ -154,7 +155,6 @@ impl<'a> CheckAllBuilder<'a> {
strict_mode_violations: self
.build_strict_mode_violations()
.into_iter()
.cloned()
.collect(),
})
}
Expand Down Expand Up @@ -239,12 +239,12 @@ impl<'a> CheckAllBuilder<'a> {
}
}

fn build_strict_mode_violations(&self) -> Vec<&'a ViolationIdentifier> {
fn build_strict_mode_violations(&self) -> Vec<Violation> {
self.found_violations
.violations
.iter()
.filter(|v| v.identifier.strict)
.map(|v| &v.identifier)
.cloned()
.collect()
}
}
Expand Down Expand Up @@ -508,6 +508,8 @@ fn remove_reference_to_dependency(
}
#[cfg(test)]
mod tests {
use std::collections::HashSet;

use crate::packs::checker::{
CheckAllResult, Violation, ViolationIdentifier,
};
Expand Down Expand Up @@ -540,7 +542,7 @@ mod tests {
}
].iter().cloned().collect(),
stale_violations: Vec::new(),
strict_mode_violations: Vec::new(),
strict_mode_violations: HashSet::new(),
};

let expected_output = "2 violation(s) detected:
Expand Down

0 comments on commit 8f8e87d

Please sign in to comment.