Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/ShellCheck/Analytics.hs
Original file line number Diff line number Diff line change
Expand Up @@ -2625,8 +2625,10 @@ prop_checkGlobsAsOptions3 = verifyNot checkGlobsAsOptions "rm -- *.txt"
prop_checkGlobsAsOptions4 = verifyNot checkGlobsAsOptions "*.txt"
prop_checkGlobsAsOptions5 = verifyNot checkGlobsAsOptions "echo 'Files:' *.txt"
prop_checkGlobsAsOptions6 = verifyNot checkGlobsAsOptions "printf '%s\\n' *"
checkGlobsAsOptions _ cmd@(T_SimpleCommand _ _ args) =
unless ((fromMaybe "" $ getCommandBasename cmd) `elem` ["echo", "printf"]) $
prop_checkGlobsAsOptions7 = verifyNot checkGlobsAsOptions "set -f; ls *"
prop_checkGlobsAsOptions8 = verifyNot checkGlobsAsOptions "set -o noglob\nrm *"
checkGlobsAsOptions params cmd@(T_SimpleCommand _ _ args) =
unless (((fromMaybe "" $ getCommandBasename cmd) `elem` ["echo", "printf"]) || hasSetF params) $
mapM_ check $ takeWhile (not . isEndOfArgs) (drop 1 args)
where
check v@(T_NormalWord _ (T_Glob id s:_)) | s == "*" || s == "?" =
Expand Down
14 changes: 14 additions & 0 deletions src/ShellCheck/AnalyzerLib.hs
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ data Parameters = Parameters {
hasInheritErrexit :: Bool,
-- Whether this script has 'set -e' anywhere.
hasSetE :: Bool,
-- Whether this script has 'set -f' anywhere.
hasSetF :: Bool,
-- Whether this script has 'set -o pipefail' anywhere.
hasPipefail :: Bool,
-- Whether this script has 'shopt -s execfail' anywhere.
Expand Down Expand Up @@ -207,6 +209,7 @@ makeParameters spec = params
rootNode = root,
shellType = fromMaybe (determineShell (asFallbackShell spec) root) $ asShellType spec,
hasSetE = containsSetE root,
hasSetF = containsSetF root,
hasLastpipe =
case shellType params of
Bash -> isOptionSet "lastpipe" root
Expand Down Expand Up @@ -262,6 +265,17 @@ containsSetE root = isNothing $ doAnalysis (guard . not . isSetE) root
_ -> False
re = mkRegex "[[:space:]]-[^-]*e"

containsSetF root = isNothing $ doAnalysis (guard . not . isSetF) root
where
isSetF t =
case t of
T_Script _ (T_Literal _ str) _ -> str `matches` re
T_SimpleCommand {} ->
t `isUnqualifiedCommand` "set" &&
("noglob" `elem` oversimplify t ||
"f" `elem` map snd (getAllFlags t))
_ -> False
re = mkRegex "[[:space:]]-[^-]*f"

containsSetOption opt root = isNothing $ doAnalysis (guard . not . isPipefail) root
where
Expand Down
Loading