Don't suggest [[..]] for sh in SC2081 (fixes #1562)
This commit is contained in:
parent
5ccaddbcc2
commit
50116e8aee
|
@ -1302,12 +1302,18 @@ prop_checkComparisonAgainstGlob3 = verify checkComparisonAgainstGlob "[ $cow = *
|
||||||
prop_checkComparisonAgainstGlob4 = verifyNot checkComparisonAgainstGlob "[ $cow = foo ]"
|
prop_checkComparisonAgainstGlob4 = verifyNot checkComparisonAgainstGlob "[ $cow = foo ]"
|
||||||
prop_checkComparisonAgainstGlob5 = verify checkComparisonAgainstGlob "[[ $cow != $bar ]]"
|
prop_checkComparisonAgainstGlob5 = verify checkComparisonAgainstGlob "[[ $cow != $bar ]]"
|
||||||
prop_checkComparisonAgainstGlob6 = verify checkComparisonAgainstGlob "[ $f != /* ]"
|
prop_checkComparisonAgainstGlob6 = verify checkComparisonAgainstGlob "[ $f != /* ]"
|
||||||
|
|
||||||
checkComparisonAgainstGlob _ (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _]))
|
checkComparisonAgainstGlob _ (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _]))
|
||||||
| op `elem` ["=", "==", "!="] =
|
| op `elem` ["=", "==", "!="] =
|
||||||
warn id 2053 $ "Quote the right-hand side of " ++ op ++ " in [[ ]] to prevent glob matching."
|
warn id 2053 $ "Quote the right-hand side of " ++ op ++ " in [[ ]] to prevent glob matching."
|
||||||
checkComparisonAgainstGlob _ (TC_Binary _ SingleBracket op _ word)
|
checkComparisonAgainstGlob params (TC_Binary _ SingleBracket op _ word)
|
||||||
| op `elem` ["=", "==", "!="] && isGlob word =
|
| op `elem` ["=", "==", "!="] && isGlob word =
|
||||||
err (getId word) 2081 "[ .. ] can't match globs. Use [[ .. ]] or case statement."
|
err (getId word) 2081 msg
|
||||||
|
where
|
||||||
|
msg = if isBashLike params
|
||||||
|
then "[ .. ] can't match globs. Use [[ .. ]] or case statement."
|
||||||
|
else "[ .. ] can't match globs. Use a case statement."
|
||||||
|
|
||||||
checkComparisonAgainstGlob _ _ = return ()
|
checkComparisonAgainstGlob _ _ = return ()
|
||||||
|
|
||||||
prop_checkCommarrays1 = verify checkCommarrays "a=(1, 2)"
|
prop_checkCommarrays1 = verify checkCommarrays "a=(1, 2)"
|
||||||
|
|
|
@ -947,5 +947,14 @@ getOpts flagTokenizer string cmd = process flags
|
||||||
|
|
||||||
supportsArrays shell = shell == Bash || shell == Ksh
|
supportsArrays shell = shell == Bash || shell == Ksh
|
||||||
|
|
||||||
|
-- Returns true if the shell is Bash or Ksh (sorry for the name, Ksh)
|
||||||
|
isBashLike :: Parameters -> Bool
|
||||||
|
isBashLike params =
|
||||||
|
case shellType params of
|
||||||
|
Bash -> True
|
||||||
|
Ksh -> True
|
||||||
|
Dash -> False
|
||||||
|
Sh -> False
|
||||||
|
|
||||||
return []
|
return []
|
||||||
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])
|
||||||
|
|
Loading…
Reference in New Issue