use std::path::PathBuf;
use xuanji::{BoundaryKind, Polarity, Severity, Violation, ViolationId};
use crate::finding::SemanticFact;
pub(crate) struct SingleModuleViolationContext<'a> {
pub(crate) module: &'a str,
pub(crate) rule: &'a str,
pub(crate) reason: &'a str,
pub(crate) severity: Severity,
pub(crate) anchor: Option<&'a str>,
}
pub(crate) fn push_single_module_violations(
violations: &mut Vec<Violation>,
context: SingleModuleViolationContext<'_>,
findings: Vec<(SemanticFact, PathBuf)>,
) {
let anchor = context.anchor.map(str::to_string);
for (finding, file) in findings {
violations.push(
Violation::new(
BoundaryKind::Semantic,
ViolationId::new(context.module, context.rule, finding.into_finding()),
context.reason.to_string(),
context.severity,
)
.with_file(Some(file.display().to_string()))
.with_anchor(anchor.clone())
.with_polarity(Polarity::DenyBreach),
);
}
}
pub(crate) struct MultiModuleViolationContext<'a> {
pub(crate) target: &'a str,
pub(crate) rule: &'a str,
pub(crate) reason: &'a str,
pub(crate) severity: Severity,
pub(crate) anchor: Option<&'a str>,
pub(crate) polarity: Polarity,
}
pub(crate) fn push_multi_module_violations(
violations: &mut Vec<Violation>,
context: MultiModuleViolationContext<'_>,
findings: Vec<(SemanticFact, String, PathBuf)>,
) {
let anchor = context.anchor.map(str::to_string);
for (finding, _module, file) in findings {
violations.push(
Violation::new(
BoundaryKind::Semantic,
ViolationId::new(context.target, context.rule, finding.into_finding()),
context.reason.to_string(),
context.severity,
)
.with_file(Some(file.display().to_string()))
.with_anchor(anchor.clone())
.with_polarity(context.polarity),
);
}
}