Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consistent strict mode violation building #10

Merged
merged 1 commit into from
Aug 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading