syncable_cli/analyzer/hadolint/rules/
dl4000.rs

1//! DL4000: MAINTAINER is deprecated
2//!
3//! The MAINTAINER instruction is deprecated. Use LABEL instead.
4
5use crate::analyzer::hadolint::parser::instruction::Instruction;
6use crate::analyzer::hadolint::rules::{simple_rule, SimpleRule};
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| {
16            !matches!(instr, Instruction::Maintainer(_))
17        },
18    )
19}
20
21#[cfg(test)]
22mod tests {
23    use super::*;
24    use crate::analyzer::hadolint::rules::{Rule, RuleState};
25
26    #[test]
27    fn test_no_maintainer() {
28        let rule = rule();
29        let mut state = RuleState::new();
30
31        let instr = Instruction::User("node".to_string());
32        rule.check(&mut state, 1, &instr, None);
33        assert!(state.failures.is_empty());
34    }
35
36    #[test]
37    fn test_with_maintainer() {
38        let rule = rule();
39        let mut state = RuleState::new();
40
41        let instr = Instruction::Maintainer("John Doe <john@example.com>".to_string());
42        rule.check(&mut state, 1, &instr, None);
43        assert_eq!(state.failures.len(), 1);
44        assert_eq!(state.failures[0].code.as_str(), "DL4000");
45    }
46}