Don't suggest grep -c when used with -o
This commit is contained in:
parent
b0dae063bf
commit
1a8e34bfea
|
@ -211,14 +211,19 @@ braceExpand (T_NormalWord id list) = take 1000 $ do
|
||||||
braceExpand item
|
braceExpand item
|
||||||
part x = return x
|
part x = return x
|
||||||
|
|
||||||
-- Maybe get the command name of a token representing a command
|
-- Maybe get a SimpleCommand from immediate wrappers like T_Redirections
|
||||||
getCommandName t =
|
getCommand t =
|
||||||
case t of
|
case t of
|
||||||
T_Redirecting _ _ w -> getCommandName w
|
T_Redirecting _ _ w -> getCommand w
|
||||||
T_SimpleCommand _ _ (w:_) -> getLiteralString w
|
T_SimpleCommand _ _ (w:_) -> return t
|
||||||
T_Annotation _ _ t -> getCommandName t
|
T_Annotation _ _ t -> getCommand t
|
||||||
otherwise -> Nothing
|
otherwise -> Nothing
|
||||||
|
|
||||||
|
-- Maybe get the command name of a token representing a command
|
||||||
|
getCommandName t = do
|
||||||
|
(T_SimpleCommand _ _ (w:_)) <- getCommand t
|
||||||
|
getLiteralString w
|
||||||
|
|
||||||
-- If a command substitution is a single command, get its name.
|
-- If a command substitution is a single command, get its name.
|
||||||
-- $(date +%s) = Just "date"
|
-- $(date +%s) = Just "date"
|
||||||
getCommandNameFromExpansion :: Token -> Maybe String
|
getCommandNameFromExpansion :: Token -> Maybe String
|
||||||
|
|
|
@ -371,6 +371,8 @@ prop_checkPipePitfalls4 = verifyNot checkPipePitfalls "find . -print0 | xargs -0
|
||||||
prop_checkPipePitfalls5 = verifyNot checkPipePitfalls "ls -N | foo"
|
prop_checkPipePitfalls5 = verifyNot checkPipePitfalls "ls -N | foo"
|
||||||
prop_checkPipePitfalls6 = verify checkPipePitfalls "find . | xargs foo"
|
prop_checkPipePitfalls6 = verify checkPipePitfalls "find . | xargs foo"
|
||||||
prop_checkPipePitfalls7 = verifyNot checkPipePitfalls "find . -printf '%s\\n' | xargs foo"
|
prop_checkPipePitfalls7 = verifyNot checkPipePitfalls "find . -printf '%s\\n' | xargs foo"
|
||||||
|
prop_checkPipePitfalls8 = verify checkPipePitfalls "foo | grep bar | wc -l"
|
||||||
|
prop_checkPipePitfalls9 = verifyNot checkPipePitfalls "foo | grep -o bar | wc -l"
|
||||||
checkPipePitfalls _ (T_Pipeline id _ commands) = do
|
checkPipePitfalls _ (T_Pipeline id _ commands) = do
|
||||||
for ["find", "xargs"] $
|
for ["find", "xargs"] $
|
||||||
\(find:xargs:_) ->
|
\(find:xargs:_) ->
|
||||||
|
@ -390,8 +392,12 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do
|
||||||
for' ["ps", "grep"] $
|
for' ["ps", "grep"] $
|
||||||
\x -> info x 2009 "Consider using pgrep instead of grepping ps output."
|
\x -> info x 2009 "Consider using pgrep instead of grepping ps output."
|
||||||
|
|
||||||
for' ["grep", "wc"] $
|
for ["grep", "wc"] $
|
||||||
\x -> style x 2126 "Consider using grep -c instead of grep|wc."
|
\(grep:wc:_) ->
|
||||||
|
let flags = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep
|
||||||
|
in
|
||||||
|
unless (any (`elem` ["o", "only-matching"]) flags) $
|
||||||
|
style (getId grep) 2126 "Consider using grep -c instead of grep|wc."
|
||||||
|
|
||||||
didLs <- liftM or . sequence $ [
|
didLs <- liftM or . sequence $ [
|
||||||
for' ["ls", "grep"] $
|
for' ["ls", "grep"] $
|
||||||
|
|
Loading…
Reference in New Issue