mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-11 23:56:30 -07:00
Added check for [[ foo == $bar ]]
This commit is contained in:
parent
a2cc44a04d
commit
686c895858
1 changed files with 8 additions and 0 deletions
|
@ -38,6 +38,7 @@ basicChecks = [
|
||||||
,checkForDecimals
|
,checkForDecimals
|
||||||
,checkDivBeforeMult
|
,checkDivBeforeMult
|
||||||
,checkArithmeticDeref
|
,checkArithmeticDeref
|
||||||
|
,checkComparisonAgainstGlob
|
||||||
]
|
]
|
||||||
|
|
||||||
modifyMap = modify
|
modifyMap = modify
|
||||||
|
@ -260,6 +261,13 @@ checkArithmeticDeref (TA_Expansion _ (T_DollarBraced id str)) | not $ any (`elem
|
||||||
addNoteFor id $ Note WarningC $ "Don't use $ on variables in (( )) unless you want to dereference twice"
|
addNoteFor id $ Note WarningC $ "Don't use $ on variables in (( )) unless you want to dereference twice"
|
||||||
checkArithmeticDeref _ = return ()
|
checkArithmeticDeref _ = return ()
|
||||||
|
|
||||||
|
|
||||||
|
prop_checkComparisonAgainstGlob = verify checkComparisonAgainstGlob "[[ $cow == $bar ]]"
|
||||||
|
prop_checkComparisonAgainstGlob2 = verifyNot checkComparisonAgainstGlob "[[ $cow == \"$bar\" ]]"
|
||||||
|
checkComparisonAgainstGlob (TC_Binary _ DoubleBracket op _ (T_NormalWord id [T_DollarBraced _ _])) | op == "=" || op == "==" =
|
||||||
|
addNoteFor id $ Note WarningC $ "Quote the rhs of = in [[ ]] to prevent glob interpretation"
|
||||||
|
checkComparisonAgainstGlob _ = return ()
|
||||||
|
|
||||||
allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables x)) t) []
|
allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables x)) t) []
|
||||||
|
|
||||||
--- Subshell detection
|
--- Subshell detection
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue