module Hadolint.Rule.DL3060 (rule) where

import Hadolint.Rule
import qualified Hadolint.Shell as Shell
import Language.Docker.Syntax


rule :: Rule Shell.ParsedShell
rule :: Rule ParsedShell
rule = RuleCode
-> DLSeverity
-> Text
-> (Instruction ParsedShell -> Bool)
-> Rule ParsedShell
forall args.
RuleCode
-> DLSeverity -> Text -> (Instruction args -> Bool) -> Rule args
simpleRule RuleCode
code DLSeverity
severity Text
message Instruction ParsedShell -> Bool
check
  where
    code :: RuleCode
code = RuleCode
"DL3060"
    severity :: DLSeverity
severity = DLSeverity
DLInfoC
    message :: Text
message = Text
"`yarn cache clean` missing after `yarn install` was run."

    check :: Instruction ParsedShell -> Bool
check (Run (RunArgs Arguments ParsedShell
args RunFlags
_)) =
      (ParsedShell -> Bool) -> Arguments ParsedShell -> Bool
forall a b. (a -> b) -> Arguments a -> b
foldArguments ((Command -> Bool) -> ParsedShell -> Bool
Shell.noCommands Command -> Bool
yarnInstall) Arguments ParsedShell
args
        Bool -> Bool -> Bool
|| ( (ParsedShell -> Bool) -> Arguments ParsedShell -> Bool
forall a b. (a -> b) -> Arguments a -> b
foldArguments ((Command -> Bool) -> ParsedShell -> Bool
Shell.anyCommands Command -> Bool
yarnInstall) Arguments ParsedShell
args
              Bool -> Bool -> Bool
&& (ParsedShell -> Bool) -> Arguments ParsedShell -> Bool
forall a b. (a -> b) -> Arguments a -> b
foldArguments ((Command -> Bool) -> ParsedShell -> Bool
Shell.anyCommands Command -> Bool
yarnCacheClean) Arguments ParsedShell
args
           )
    check Instruction ParsedShell
_ = Bool
True
{-# INLINEABLE rule #-}

yarnInstall :: Shell.Command -> Bool
yarnInstall :: Command -> Bool
yarnInstall = Text -> [Text] -> Command -> Bool
Shell.cmdHasArgs Text
"yarn" [Text
"install"]

yarnCacheClean :: Shell.Command -> Bool
yarnCacheClean :: Command -> Bool
yarnCacheClean = Text -> [Text] -> Command -> Bool
Shell.cmdHasArgs Text
"yarn" [Text
"cache", Text
"clean"]