mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-08 17:11:00 +08:00
Don't consider ~foo constant.
This commit is contained in:
@@ -55,6 +55,8 @@ isGlob _ = False
|
|||||||
-- Is this shell word a constant?
|
-- Is this shell word a constant?
|
||||||
isConstant token =
|
isConstant token =
|
||||||
case token of
|
case token of
|
||||||
|
-- This ignores some cases like ~"foo":
|
||||||
|
T_NormalWord _ (T_Literal _ ('~':_) : _) -> False
|
||||||
T_NormalWord _ l -> all isConstant l
|
T_NormalWord _ l -> all isConstant l
|
||||||
T_DoubleQuoted _ l -> all isConstant l
|
T_DoubleQuoted _ l -> all isConstant l
|
||||||
T_SingleQuoted _ _ -> True
|
T_SingleQuoted _ _ -> True
|
||||||
|
@@ -1251,12 +1251,11 @@ prop_checkConstantIfs4 = verifyNot checkConstantIfs "[[ $n -le 3 ]]"
|
|||||||
prop_checkConstantIfs5 = verifyNot checkConstantIfs "[[ $n -le $n ]]"
|
prop_checkConstantIfs5 = verifyNot checkConstantIfs "[[ $n -le $n ]]"
|
||||||
prop_checkConstantIfs6 = verifyNot checkConstantIfs "[[ a -ot b ]]"
|
prop_checkConstantIfs6 = verifyNot checkConstantIfs "[[ a -ot b ]]"
|
||||||
prop_checkConstantIfs7 = verifyNot checkConstantIfs "[ a -nt b ]"
|
prop_checkConstantIfs7 = verifyNot checkConstantIfs "[ a -nt b ]"
|
||||||
|
prop_checkConstantIfs8 = verifyNot checkConstantIfs "[[ ~foo == '~foo' ]]"
|
||||||
checkConstantIfs _ (TC_Binary id typ op lhs rhs) | not isDynamic =
|
checkConstantIfs _ (TC_Binary id typ op lhs rhs) | not isDynamic =
|
||||||
when (isJust lLit && isJust rLit) $
|
when (isConstant lhs && isConstant rhs) $
|
||||||
warn id 2050 "This expression is constant. Did you forget the $ on a variable?"
|
warn id 2050 "This expression is constant. Did you forget the $ on a variable?"
|
||||||
where
|
where
|
||||||
lLit = getLiteralString lhs
|
|
||||||
rLit = getLiteralString rhs
|
|
||||||
isDynamic =
|
isDynamic =
|
||||||
op `elem` [ "-lt", "-gt", "-le", "-ge", "-eq", "-ne" ]
|
op `elem` [ "-lt", "-gt", "-le", "-ge", "-eq", "-ne" ]
|
||||||
&& typ == DoubleBracket
|
&& typ == DoubleBracket
|
||||||
|
Reference in New Issue
Block a user