Merge pull request #2586 from DoxasticFox/issue-2537

Suppress SC2311 with `set -o posix`
This commit is contained in:
Vidar Holen 2022-09-25 11:04:30 -07:00 committed by GitHub
commit bd65b67578
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 12 deletions

View File

@ -4687,6 +4687,7 @@ prop_checkSetESuppressed15 = verifyTree checkSetESuppressed "set -e; f(){ :;
prop_checkSetESuppressed16 = verifyTree checkSetESuppressed "set -e; f(){ :; }; until set -e; f; do :; done" prop_checkSetESuppressed16 = verifyTree checkSetESuppressed "set -e; f(){ :; }; until set -e; f; do :; done"
prop_checkSetESuppressed17 = verifyNotTree checkSetESuppressed "set -e; f(){ :; }; g(){ :; }; g f" prop_checkSetESuppressed17 = verifyNotTree checkSetESuppressed "set -e; f(){ :; }; g(){ :; }; g f"
prop_checkSetESuppressed18 = verifyNotTree checkSetESuppressed "set -e; shopt -s inherit_errexit; f(){ :; }; x=$(f)" prop_checkSetESuppressed18 = verifyNotTree checkSetESuppressed "set -e; shopt -s inherit_errexit; f(){ :; }; x=$(f)"
prop_checkSetESuppressed19 = verifyNotTree checkSetESuppressed "set -e; set -o posix; f(){ :; }; x=$(f)"
checkSetESuppressed params t = checkSetESuppressed params t =
if hasSetE params then runNodeAnalysis checkNode params t else [] if hasSetE params then runNodeAnalysis checkNode params t else []
where where

View File

@ -203,22 +203,22 @@ makeParameters spec = params
hasSetE = containsSetE root, hasSetE = containsSetE root,
hasLastpipe = hasLastpipe =
case shellType params of case shellType params of
Bash -> containsLastpipe root Bash -> isOptionSet "lastpipe" root
Dash -> False Dash -> False
Sh -> False Sh -> False
Ksh -> True, Ksh -> True,
hasInheritErrexit = hasInheritErrexit =
case shellType params of case shellType params of
Bash -> containsInheritErrexit root Bash -> isOptionSet "inherit_errexit" root
Dash -> True Dash -> True
Sh -> True Sh -> True
Ksh -> False, Ksh -> False,
hasPipefail = hasPipefail =
case shellType params of case shellType params of
Bash -> containsPipefail root Bash -> isOptionSet "pipefail" root
Dash -> True Dash -> True
Sh -> True Sh -> True
Ksh -> containsPipefail root, Ksh -> isOptionSet "pipefail" root,
shellTypeSpecified = isJust (asShellType spec) || isJust (asFallbackShell spec), shellTypeSpecified = isJust (asShellType spec) || isJust (asFallbackShell spec),
idMap = getTokenMap root, idMap = getTokenMap root,
parentMap = getParentTree root, parentMap = getParentTree root,
@ -247,13 +247,14 @@ containsSetE root = isNothing $ doAnalysis (guard . not . isSetE) root
_ -> False _ -> False
re = mkRegex "[[:space:]]-[^-]*e" re = mkRegex "[[:space:]]-[^-]*e"
containsPipefail root = isNothing $ doAnalysis (guard . not . isPipefail) root
containsSetOption opt root = isNothing $ doAnalysis (guard . not . isPipefail) root
where where
isPipefail t = isPipefail t =
case t of case t of
T_SimpleCommand {} -> T_SimpleCommand {} ->
t `isUnqualifiedCommand` "set" && t `isUnqualifiedCommand` "set" &&
("pipefail" `elem` oversimplify t || (opt `elem` oversimplify t ||
"o" `elem` map snd (getAllFlags t)) "o" `elem` map snd (getAllFlags t))
_ -> False _ -> False
@ -267,12 +268,8 @@ containsShopt shopt root =
(shopt `elem` oversimplify t) (shopt `elem` oversimplify t)
_ -> False _ -> False
-- Does this script mention 'shopt -s inherit_errexit' anywhere? -- Does this script mention 'shopt -s $opt' or 'set -o $opt' anywhere?
containsInheritErrexit = containsShopt "inherit_errexit" isOptionSet opt root = containsShopt opt root || containsSetOption opt root
-- Does this script mention 'shopt -s lastpipe' anywhere?
-- Also used as a hack.
containsLastpipe = containsShopt "lastpipe"
prop_determineShell0 = determineShellTest "#!/bin/sh" == Sh prop_determineShell0 = determineShellTest "#!/bin/sh" == Sh