syncable_cli/analyzer/hadolint/rules/
dl3049.rs

1//! DL3049: Label `maintainer` is deprecated
2//!
3//! The maintainer label is deprecated. Use org.opencontainers.image.authors instead.
4
5use 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        "DL3049",
13        Severity::Info,
14        "Label `maintainer` is deprecated, use `org.opencontainers.image.authors` instead.",
15        |instr, _shell| match instr {
16            Instruction::Label(pairs) => !pairs
17                .iter()
18                .any(|(key, _)| key.to_lowercase() == "maintainer"),
19            _ => true,
20        },
21    )
22}
23
24#[cfg(test)]
25mod tests {
26    use super::*;
27    use crate::analyzer::hadolint::config::HadolintConfig;
28    use crate::analyzer::hadolint::lint::{LintResult, lint};
29
30    fn lint_dockerfile(content: &str) -> LintResult {
31        lint(content, &HadolintConfig::default())
32    }
33
34    #[test]
35    fn test_maintainer_label() {
36        let result = lint_dockerfile("FROM ubuntu:20.04\nLABEL maintainer=\"test@test.com\"");
37        assert!(result.failures.iter().any(|f| f.code.as_str() == "DL3049"));
38    }
39
40    #[test]
41    fn test_oci_authors_label() {
42        let result = lint_dockerfile(
43            "FROM ubuntu:20.04\nLABEL org.opencontainers.image.authors=\"test@test.com\"",
44        );
45        assert!(!result.failures.iter().any(|f| f.code.as_str() == "DL3049"));
46    }
47}