Don't warn about grep pattern issues when using -F.

This commit is contained in:
Vidar Holen 2017-01-21 16:20:55 -08:00
parent 41176c23a6
commit 128d5d6013
2 changed files with 19 additions and 12 deletions

View File

@ -93,7 +93,7 @@ oversimplify token =
(T_Annotation _ _ s) -> oversimplify s (T_Annotation _ _ s) -> oversimplify s
-- Workaround for let "foo = bar" parsing -- Workaround for let "foo = bar" parsing
(TA_Sequence _ [TA_Expansion _ v]) -> concatMap oversimplify v (TA_Sequence _ [TA_Expansion _ v]) -> concatMap oversimplify v
otherwise -> [] _ -> []
-- Turn a SimpleCommand foo -avz --bar=baz into args "a", "v", "z", "bar", -- Turn a SimpleCommand foo -avz --bar=baz into args "a", "v", "z", "bar",
@ -115,6 +115,9 @@ getAllFlags = getFlagsUntil (== "--")
-- Get all flags in a BSD way, up until first non-flag argument or -- -- Get all flags in a BSD way, up until first non-flag argument or --
getLeadingFlags = getFlagsUntil (\x -> x == "--" || (not $ "-" `isPrefixOf` x)) getLeadingFlags = getFlagsUntil (\x -> x == "--" || (not $ "-" `isPrefixOf` x))
-- Check if a command has a flag.
hasFlag cmd str = str `elem` (map snd $ getAllFlags cmd)
-- Given a T_DollarBraced, return a simplified version of the string contents. -- Given a T_DollarBraced, return a simplified version of the string contents.
bracedString (T_DollarBraced _ l) = concat $ oversimplify l bracedString (T_DollarBraced _ l) = concat $ oversimplify l

View File

@ -194,16 +194,20 @@ prop_checkGrepRe8 = verify checkGrepRe "ls | grep foo*.jpg"
prop_checkGrepRe9 = verifyNot checkGrepRe "grep '[0-9]*' file" prop_checkGrepRe9 = verifyNot checkGrepRe "grep '[0-9]*' file"
prop_checkGrepRe10= verifyNot checkGrepRe "grep '^aa*' file" prop_checkGrepRe10= verifyNot checkGrepRe "grep '^aa*' file"
prop_checkGrepRe11= verifyNot checkGrepRe "grep --include=*.png foo" prop_checkGrepRe11= verifyNot checkGrepRe "grep --include=*.png foo"
prop_checkGrepRe12= verifyNot checkGrepRe "grep -F 'Foo*' file"
checkGrepRe = CommandCheck (Basename "grep") (f . arguments) where checkGrepRe = CommandCheck (Basename "grep") check where
check cmd = f cmd (arguments cmd)
-- --regex=*(extglob) doesn't work. Fixme? -- --regex=*(extglob) doesn't work. Fixme?
skippable (Just s) = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s skippable (Just s) = not ("--regex=" `isPrefixOf` s) && "-" `isPrefixOf` s
skippable _ = False skippable _ = False
f [] = return () f _ [] = return ()
f (x:r) | skippable (getLiteralStringExt (const $ return "_") x) = f r f cmd (x:r) | skippable (getLiteralStringExt (const $ return "_") x) = f cmd r
f (re:_) = do f cmd (re:_) = do
when (isGlob re) $ when (isGlob re) $
warn (getId re) 2062 "Quote the grep pattern so the shell won't interpret it." warn (getId re) 2062 "Quote the grep pattern so the shell won't interpret it."
unless (cmd `hasFlag` "F") $ do
let string = concat $ oversimplify re let string = concat $ oversimplify re
if isConfusedGlobRegex string then if isConfusedGlobRegex string then
warn (getId re) 2063 "Grep uses regex, but this looks like a glob." warn (getId re) 2063 "Grep uses regex, but this looks like a glob."