syncable_cli/analyzer/hadolint/rules/
dl3039.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 "DL3039",
13 Severity::Warning,
14 "Do not use `dnf update`.",
15 |instr, shell| {
16 match instr {
17 Instruction::Run(_) => {
18 if let Some(shell) = shell {
19 !shell.any_command(|cmd| {
20 cmd.name == "dnf" && cmd.has_any_arg(&["update", "upgrade"])
21 })
22 } else {
23 true
24 }
25 }
26 _ => true,
27 }
28 },
29 )
30}
31
32#[cfg(test)]
33mod tests {
34 use super::*;
35 use crate::analyzer::hadolint::lint::{lint, LintResult};
36 use crate::analyzer::hadolint::config::HadolintConfig;
37
38 fn lint_dockerfile(content: &str) -> LintResult {
39 lint(content, &HadolintConfig::default())
40 }
41
42 #[test]
43 fn test_dnf_update() {
44 let result = lint_dockerfile("FROM fedora:latest\nRUN dnf update -y");
45 assert!(result.failures.iter().any(|f| f.code.as_str() == "DL3039"));
46 }
47
48 #[test]
49 fn test_dnf_install() {
50 let result = lint_dockerfile("FROM fedora:latest\nRUN dnf install -y nginx");
51 assert!(!result.failures.iter().any(|f| f.code.as_str() == "DL3039"));
52 }
53}