hadolint-2.15.0: src/Hadolint/Rule/DL3040.hs
module Hadolint.Rule.DL3040 (rule) where
import Hadolint.Rule
import qualified Hadolint.Shell as Shell
import qualified Hadolint.Utils as Utils
import Language.Docker.Syntax
rule :: Rule Shell.ParsedShell
rule = dl3040 <> onbuild dl3040
{-# INLINEABLE rule #-}
dl3040 :: Rule Shell.ParsedShell
dl3040 = simpleRule code severity message check
where
code = "DL3040"
severity = DLWarningC
message = "`dnf clean all` missing after dnf command."
check (Run (RunArgs args flags))
| all (checkMissingClean args) dnfCmds = True
| Utils.hasCacheOrTmpfsMountWith "/var/cache/libdnf5" flags = True
| Utils.hasCacheOrTmpfsMountWith ".cache/libdnf5" flags = True
| otherwise = False
check _ = True
checkMissingClean args cmdName =
foldArguments (Shell.noCommands $ dnfInstall cmdName) args
|| Just True == (
(<) <$> foldArguments (Shell.findCommandIndex $ dnfInstall cmdName) args
<*> foldArguments (Shell.findCommandIndex $ dnfClean cmdName) args)
dnfInstall cmdName args = ( cmdName `elem` dnfCmds )
&& Shell.cmdHasArgs cmdName installCmds args
dnfClean cmdName args = Shell.cmdHasArgs cmdName ["clean", "all"] args
|| Shell.cmdHasArgs "rm" ["-rf", "/var/cache/libdnf5*"] args
dnfCmds = ["dnf", "microdnf"]
installCmds = ["install", "in", "upgrade", "up", "upgrade-minimal", "up-min", "reinstall", "rei"]
{-# INLINEABLE dl3040 #-}