Skip to content

Commit

Permalink
DL3060: fix: check clean after yarn install
Browse files Browse the repository at this point in the history
  • Loading branch information
Mateusz Marczak committed Jun 14, 2023
1 parent d98b136 commit 5bc5f38
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/Hadolint/Rule/DL3060.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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 (

Check warning on line 35 in src/Hadolint/Rule/DL3060.hs

View workflow job for this annotation

GitHub Actions / hlint

Warning in dl3060 in module Hadolint.Rule.DL3060: Use Just ▫︎ Found: "fromMaybe\n False\n ((<) <$> foldArguments (Shell.findCommandIndex yarnInstall) args\n <*> foldArguments (Shell.findCommandIndex yarnCacheClean) args)" ▫︎ Perhaps: "Just True\n ==\n ((<) <$> foldArguments (Shell.findCommandIndex yarnInstall) args\n <*> foldArguments (Shell.findCommandIndex yarnCacheClean) args)"
(<) <$> foldArguments (Shell.findCommandIndex yarnInstall) args
<*> foldArguments (Shell.findCommandIndex yarnCacheClean) args) =
st |> modify (rememberLine line)
| otherwise = st
check _ st _ = st

Expand Down
2 changes: 2 additions & 0 deletions test/Hadolint/Rule/DL3060Spec.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down

0 comments on commit 5bc5f38

Please sign in to comment.