Skip to content

Commit

Permalink
Don't suggset quoting in grep -- -foo bar* (koalaman#517)
Browse files Browse the repository at this point in the history
  • Loading branch information
koalaman committed Sep 9, 2017
1 parent bd2facb commit b0f6f93
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions ShellCheck/Checks/Commands.hs
Original file line number Diff line number Diff line change
Expand Up @@ -198,15 +198,26 @@ prop_checkGrepRe9 = verifyNot checkGrepRe "grep '[0-9]*' file"
prop_checkGrepRe10= verifyNot checkGrepRe "grep '^aa*' file"
prop_checkGrepRe11= verifyNot checkGrepRe "grep --include=*.png foo"
prop_checkGrepRe12= verifyNot checkGrepRe "grep -F 'Foo*' file"
prop_checkGrepRe13= verifyNot checkGrepRe "grep -- -foo bar*"

checkGrepRe = CommandCheck (Basename "grep") check where
check cmd = f cmd (arguments cmd)
-- --regex=*(extglob) doesn't work. Fixme?
skippable (Just s) = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s
skippable _ = False
f _ [] = return ()
f cmd (x:r) | skippable (getLiteralStringExt (const $ return "_") x) = f cmd r
f cmd (re:_) = do
f cmd (x:r) =
let str = getLiteralStringExt (const $ return "_") x
in
if str == Just "--"
then checkRE cmd r -- Regex is *after* this
else
if skippable str
then f cmd r -- Regex is elsewhere
else checkRE cmd (x:r) -- Regex is this

checkRE _ [] = return ()
checkRE cmd (re:_) = do
when (isGlob re) $
warn (getId re) 2062 "Quote the grep pattern so the shell won't interpret it."

Expand Down

0 comments on commit b0f6f93

Please sign in to comment.