From 5bc5f383e12ddea9cfe26d600ab9e0cf8cac0172 Mon Sep 17 00:00:00 2001 From: Mateusz Marczak Date: Wed, 14 Jun 2023 12:37:22 +0200 Subject: [PATCH] DL3060: fix: check clean after yarn install --- src/Hadolint/Rule/DL3060.hs | 8 +++++--- test/Hadolint/Rule/DL3060Spec.hs | 2 ++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/Hadolint/Rule/DL3060.hs b/src/Hadolint/Rule/DL3060.hs index 77c20949..f91d60ad 100644 --- a/src/Hadolint/Rule/DL3060.hs +++ b/src/Hadolint/Rule/DL3060.hs @@ -2,6 +2,7 @@ module Hadolint.Rule.DL3060 (rule) where import qualified Data.Map.Strict as Map import qualified Data.Text as Text +import Data.Maybe (fromMaybe) import Hadolint.Rule import qualified Hadolint.Shell as Shell import Language.Docker.Syntax @@ -31,9 +32,10 @@ dl3060 = veryCustomRule check (emptyState Empty) markFailures check line st (From from) = st |> modify (rememberStage line from) check line st (Run (RunArgs args _)) - | foldArguments (Shell.anyCommands yarnInstall) args - && foldArguments (Shell.noCommands yarnCacheClean) args = - st |> modify (rememberLine line) + | fromMaybe False ( + (<) <$> foldArguments (Shell.findCommandIndex yarnInstall) args + <*> foldArguments (Shell.findCommandIndex yarnCacheClean) args) = + st |> modify (rememberLine line) | otherwise = st check _ st _ = st diff --git a/test/Hadolint/Rule/DL3060Spec.hs b/test/Hadolint/Rule/DL3060Spec.hs index 6c05b0c6..98b8fcdb 100644 --- a/test/Hadolint/Rule/DL3060Spec.hs +++ b/test/Hadolint/Rule/DL3060Spec.hs @@ -20,6 +20,8 @@ spec = do it "ok with cache clean" $ do ruleCatchesNot "DL3060" "RUN yarn install bar && yarn cache clean" onBuildRuleCatchesNot "DL3060" "RUN yarn install bar && yarn cache clean" + it "not ok with clean before install" $ do + ruleCatches "DL3040" "RUN yarn cache clean && yarn install foo" it "not ok when yarn install is in last stage w/o yarn clean" $ let dockerFile =