syncable_cli/analyzer/hadolint/rules/
dl4000.rs1use crate::analyzer::hadolint::parser::instruction::Instruction;
6use crate::analyzer::hadolint::rules::{SimpleRule, simple_rule};
7use crate::analyzer::hadolint::shell::ParsedShell;
8use crate::analyzer::hadolint::types::Severity;
9
10pub fn rule() -> SimpleRule<impl Fn(&Instruction, Option<&ParsedShell>) -> bool + Send + Sync> {
11 simple_rule(
12 "DL4000",
13 Severity::Error,
14 "MAINTAINER is deprecated",
15 |instr, _shell| !matches!(instr, Instruction::Maintainer(_)),
16 )
17}
18
19#[cfg(test)]
20mod tests {
21 use super::*;
22 use crate::analyzer::hadolint::rules::{Rule, RuleState};
23
24 #[test]
25 fn test_no_maintainer() {
26 let rule = rule();
27 let mut state = RuleState::new();
28
29 let instr = Instruction::User("node".to_string());
30 rule.check(&mut state, 1, &instr, None);
31 assert!(state.failures.is_empty());
32 }
33
34 #[test]
35 fn test_with_maintainer() {
36 let rule = rule();
37 let mut state = RuleState::new();
38
39 let instr = Instruction::Maintainer("John Doe <john@example.com>".to_string());
40 rule.check(&mut state, 1, &instr, None);
41 assert_eq!(state.failures.len(), 1);
42 assert_eq!(state.failures[0].code.as_str(), "DL4000");
43 }
44}