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