mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-07 13:31:36 -07:00
Account for BusyBox support of [[ ]] (fixes #2967)
This commit is contained in:
parent
a13cb85f49
commit
ac8fb00504
3 changed files with 10 additions and 13 deletions
|
@ -1525,6 +1525,7 @@ prop_checkComparisonAgainstGlob3 = verify checkComparisonAgainstGlob "[ $cow = *
|
|||
prop_checkComparisonAgainstGlob4 = verifyNot checkComparisonAgainstGlob "[ $cow = foo ]"
|
||||
prop_checkComparisonAgainstGlob5 = verify checkComparisonAgainstGlob "[[ $cow != $bar ]]"
|
||||
prop_checkComparisonAgainstGlob6 = verify checkComparisonAgainstGlob "[ $f != /* ]"
|
||||
prop_checkComparisonAgainstGlob7 = verify checkComparisonAgainstGlob "#!/bin/busybox sh\n[[ $f == *foo* ]]"
|
||||
checkComparisonAgainstGlob _ (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _ _]))
|
||||
| op `elem` ["=", "==", "!="] =
|
||||
warn id 2053 $ "Quote the right-hand side of " ++ op ++ " in [[ ]] to prevent glob matching."
|
||||
|
@ -1532,10 +1533,14 @@ checkComparisonAgainstGlob params (TC_Binary _ SingleBracket op _ word)
|
|||
| op `elem` ["=", "==", "!="] && isGlob word =
|
||||
err (getId word) 2081 msg
|
||||
where
|
||||
msg = if isBashLike params
|
||||
msg = if (shellType params) `elem` [Bash, Ksh] -- Busybox does not support glob matching
|
||||
then "[ .. ] can't match globs. Use [[ .. ]] or case statement."
|
||||
else "[ .. ] can't match globs. Use a case statement."
|
||||
|
||||
checkComparisonAgainstGlob params (TC_Binary _ DoubleBracket op _ word)
|
||||
| shellType params == BusyboxSh && op `elem` ["=", "==", "!="] && isGlob word =
|
||||
err (getId word) 2330 "BusyBox [[ .. ]] does not support glob matching. Use a case statement."
|
||||
|
||||
checkComparisonAgainstGlob _ _ = return ()
|
||||
|
||||
prop_checkCaseAgainstGlob1 = verify checkCaseAgainstGlob "case foo in lol$n) foo;; esac"
|
||||
|
@ -4534,13 +4539,13 @@ prop_checkRequireDoubleBracket2 = verifyTree checkRequireDoubleBracket "[ foo -o
|
|||
prop_checkRequireDoubleBracket3 = verifyNotTree checkRequireDoubleBracket "#!/bin/sh\n[ -x foo ]"
|
||||
prop_checkRequireDoubleBracket4 = verifyNotTree checkRequireDoubleBracket "[[ -x foo ]]"
|
||||
checkRequireDoubleBracket params =
|
||||
if isBashLike params
|
||||
if (shellType params) `elem` [Bash, Ksh, BusyboxSh]
|
||||
then nodeChecksToTreeCheck [check] params
|
||||
else const []
|
||||
where
|
||||
check _ t = case t of
|
||||
T_Condition id SingleBracket _ ->
|
||||
styleWithFix id 2292 "Prefer [[ ]] over [ ] for tests in Bash/Ksh." (fixFor t)
|
||||
styleWithFix id 2292 "Prefer [[ ]] over [ ] for tests in Bash/Ksh/Busybox." (fixFor t)
|
||||
_ -> return ()
|
||||
|
||||
fixFor t = fixWith $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue