syncable_cli/analyzer/hadolint/rules/
dl3054.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 "DL3054",
13 Severity::Warning,
14 "Label `org.opencontainers.image.description` is empty.",
15 |instr, _shell| match instr {
16 Instruction::Label(pairs) => {
17 for (key, value) in pairs {
18 if key == "org.opencontainers.image.description" && value.trim().is_empty() {
19 return false;
20 }
21 }
22 true
23 }
24 _ => true,
25 },
26 )
27}
28
29#[cfg(test)]
30mod tests {
31 use super::*;
32 use crate::analyzer::hadolint::config::HadolintConfig;
33 use crate::analyzer::hadolint::lint::{LintResult, lint};
34
35 fn lint_dockerfile(content: &str) -> LintResult {
36 lint(content, &HadolintConfig::default())
37 }
38
39 #[test]
40 fn test_valid_description() {
41 let result = lint_dockerfile(
42 "FROM ubuntu:20.04\nLABEL org.opencontainers.image.description=\"A description\"",
43 );
44 assert!(!result.failures.iter().any(|f| f.code.as_str() == "DL3054"));
45 }
46
47 #[test]
48 fn test_empty_description() {
49 let result =
50 lint_dockerfile("FROM ubuntu:20.04\nLABEL org.opencontainers.image.description=\"\"");
51 assert!(result.failures.iter().any(|f| f.code.as_str() == "DL3054"));
52 }
53}