diff --git a/ShellCheck/ASTLib.hs b/ShellCheck/ASTLib.hs index 59167c7..e8ecb85 100644 --- a/ShellCheck/ASTLib.hs +++ b/ShellCheck/ASTLib.hs @@ -55,6 +55,8 @@ isGlob _ = False -- Is this shell word a constant? isConstant token = case token of + -- This ignores some cases like ~"foo": + T_NormalWord _ (T_Literal _ ('~':_) : _) -> False T_NormalWord _ l -> all isConstant l T_DoubleQuoted _ l -> all isConstant l T_SingleQuoted _ _ -> True diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 01c0a14..77898ce 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -1251,12 +1251,11 @@ prop_checkConstantIfs4 = verifyNot checkConstantIfs "[[ $n -le 3 ]]" prop_checkConstantIfs5 = verifyNot checkConstantIfs "[[ $n -le $n ]]" prop_checkConstantIfs6 = verifyNot checkConstantIfs "[[ a -ot b ]]" prop_checkConstantIfs7 = verifyNot checkConstantIfs "[ a -nt b ]" +prop_checkConstantIfs8 = verifyNot checkConstantIfs "[[ ~foo == '~foo' ]]" 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?" where - lLit = getLiteralString lhs - rLit = getLiteralString rhs isDynamic = op `elem` [ "-lt", "-gt", "-le", "-ge", "-eq", "-ne" ] && typ == DoubleBracket