From e8a2ac09c78539df144339ebfe12e01679810308 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 27 Nov 2012 20:26:41 -0800 Subject: [PATCH] Added check for grep foo* --- ShellCheck/Analytics.hs | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 2647c37..9263f1a 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -68,6 +68,7 @@ basicChecks = [ ,checkAssignAteCommand ,checkUuoe ,checkFindNameGlob + ,checkGrepRe ] modifyMap = modify @@ -519,6 +520,21 @@ checkFindNameGlob = checkCommand "find" f where f (b:r) +prop_checkGrepRe1 = verify checkGrepRe "cat foo | grep *.mp3" +prop_checkGrepRe2 = verify checkGrepRe "grep -Ev cow*test *.mp3" +prop_checkGrepRe3 = verify checkGrepRe "grep --regex=*.mp3 file" +prop_checkGrepRe4 = verifyNot checkGrepRe "grep foo *.mp3" +prop_checkGrepRe5 = verifyNot checkGrepRe "grep-v --regex=moo *" +checkGrepRe = checkCommand "grep" f where + -- --regex=*(extglob) doesn't work. Fixme? + skippable (Just s) = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s + skippable _ = False + f [] = return () + f (x:r) | skippable (getLiteralString x) = f r + f (re:_) = do + when (isGlob re) $ do + warn (getId re) $ "Quote the grep pattern so the shell won't interpret it." + --- Subshell detection