use crate::analyzer::hadolint::parser::instruction::Instruction;
use crate::analyzer::hadolint::rules::{SimpleRule, simple_rule};
use crate::analyzer::hadolint::shell::ParsedShell;
use crate::analyzer::hadolint::types::Severity;
pub fn rule() -> SimpleRule<impl Fn(&Instruction, Option<&ParsedShell>) -> bool + Send + Sync> {
simple_rule(
"DL1001",
Severity::Info,
"Please refrain from using inline ignore pragmas `# hadolint ignore=...`.",
|instr, _shell| {
match instr {
Instruction::Comment(comment) => {
let lower = comment.to_lowercase();
!lower.contains("hadolint") || !lower.contains("ignore")
}
_ => true,
}
},
)
}
#[cfg(test)]
mod tests {
use super::*;
use crate::analyzer::hadolint::rules::{Rule, RuleState};
#[test]
fn test_ignore_pragma() {
let rule = rule();
let mut state = RuleState::new();
let instr = Instruction::Comment("hadolint ignore=DL3008".to_string());
rule.check(&mut state, 1, &instr, None);
assert_eq!(state.failures.len(), 1);
}
#[test]
fn test_regular_comment() {
let rule = rule();
let mut state = RuleState::new();
let instr = Instruction::Comment("This is a regular comment".to_string());
rule.check(&mut state, 1, &instr, None);
assert!(state.failures.is_empty());
}
}