From f9f2982c9f96cc92eb4ce7849f021c80e65abf96 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 8 Nov 2012 20:43:51 -0800 Subject: [PATCH] Added check for [ a==b ] --- ShellCheck/Analytics.hs | 8 ++++++++ ShellCheck/Parser.hs | 1 - 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 8aa4deb..54d8463 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -33,6 +33,7 @@ basicChecks = [ ,checkSingleQuotedVariables ,checkUnquotedZN ,checkNumberComparisons + ,checkNoaryWasBinary ] modifyMap = modify @@ -225,6 +226,13 @@ checkNumberComparisons (TC_Binary id typ op lhs rhs) eqv _ = "the numerical equivalent" checkNumberComparisons _ = return () +prop_checkNoaryWasBinary = verify checkNoaryWasBinary "[[ a==$foo ]]" +prop_checkNoaryWasBinary2 = verify checkNoaryWasBinary "[ $foo=3 ]" +checkNoaryWasBinary (TC_Noary _ _ t@(T_NormalWord id l)) = do + let str = concat $ deadSimple t + when ('=' `elem` str) $ addNoteFor id $ Note ErrorC $ "Always true because you didn't put spaces around the =" +checkNoaryWasBinary _ = return () + allModifiedVariables t = snd $ runState (doAnalysis (\x -> modify $ (++) (getModifiedVariables t)) t) [] --- Subshell detection diff --git a/ShellCheck/Parser.hs b/ShellCheck/Parser.hs index 7814cab..b2044fb 100644 --- a/ShellCheck/Parser.hs +++ b/ShellCheck/Parser.hs @@ -146,7 +146,6 @@ acceptButWarn parser level note = do ) -prop_readConditionContents = isWarning readCondition "[ grep -q file dir ]" readConditionContents single = do readCondOr `attempting` (lookAhead $ do pos <- getPosition