syncable_cli/analyzer/hadolint/rules/
dl3053.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 "DL3053",
13 Severity::Warning,
14 "Label `org.opencontainers.image.title` is empty.",
15 |instr, _shell| match instr {
16 Instruction::Label(pairs) => {
17 for (key, value) in pairs {
18 if key == "org.opencontainers.image.title" && 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_title() {
41 let result =
42 lint_dockerfile("FROM ubuntu:20.04\nLABEL org.opencontainers.image.title=\"My App\"");
43 assert!(!result.failures.iter().any(|f| f.code.as_str() == "DL3053"));
44 }
45
46 #[test]
47 fn test_empty_title() {
48 let result =
49 lint_dockerfile("FROM ubuntu:20.04\nLABEL org.opencontainers.image.title=\"\"");
50 assert!(result.failures.iter().any(|f| f.code.as_str() == "DL3053"));
51 }
52}