27 lines
759 B
Rust
27 lines
759 B
Rust
//! Graduated check rules: project-defined patterns that flag matching
|
|||
|
|
//! file paths or content for review during write/edit operations.
|
||
|
|
|
||
|
|
/// A project-defined rule that flags a matching file path or content pattern
|
||
|
|
/// for review.
|
||
|
|
#[derive(Debug, Clone)]
|
||
|
|
pub struct GraduatedCheck {
|
||
|
|
pub name: String,
|
||
|
|
pub pattern: String,
|
||
|
|
pub rule: String,
|
||
|
|
}
|
||
|
|
|
||
|
|
/// Check which graduated checks apply to a given file path/content pair.
|
||
|
|
pub fn check_graduated_checks(
|
||
|
|
path: &str,
|
||
|
|
content: &str,
|
||
|
|
checks: &[GraduatedCheck],
|
||
|
|
) -> Vec<String> {
|
||
|
|
let mut matches = Vec::new();
|
||
|
|
for check in checks {
|
||
|
|
if path.contains(&check.pattern) || content.contains(&check.rule) {
|
||
|
|
matches.push(check.name.clone());
|
||
|
|
}
|
||
|
|
}
|
||
|
|
matches
|
||
|
|
}
|