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