From 96168fc707380c984e0f5a26062c2ed00ddd46cc Mon Sep 17 00:00:00 2001 From: Scorpiokat Date: Mon, 2 Jan 2017 18:01:24 +0000 Subject: [PATCH 1/4] This commit fixes #797 --- ShellCheck/Analytics.hs | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 017f4bc..f1be786 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -328,6 +328,12 @@ prop_checkPipePitfalls6 = verify checkPipePitfalls "find . | 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" +prop_checkPipePitfalls10 = verifyNot checkPipePitfalls "foo | grep -o bar | wc" +prop_checkPipePitfalls11 = verifyNot checkPipePitfalls "foo | grep bar | wc" +prop_checkPipePitfalls12 = verifyNot checkPipePitfalls "foo | grep -o bar | wc -c" +prop_checkPipePitfalls13 = verifyNot checkPipePitfalls "foo | grep bar | wc -c" +prop_checkPipePitfalls14 = verifyNot checkPipePitfalls "foo | grep -o bar | wc -cmwL" +prop_checkPipePitfalls15 = verifyNot checkPipePitfalls "foo | grep bar | wc -cmwL" checkPipePitfalls _ (T_Pipeline id _ commands) = do for ["find", "xargs"] $ \(find:xargs:_) -> @@ -349,10 +355,11 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do for ["grep", "wc"] $ \(grep:wc:_) -> - let flags = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep + let flagsGrep = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep + flagsWc = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand wc in - unless (any (`elem` ["o", "only-matching"]) flags) $ - style (getId grep) 2126 "Consider using grep -c instead of grep|wc." + unless ((any (`elem` ["o", "only-matching"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ + style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." didLs <- liftM or . sequence $ [ for' ["ls", "grep"] $ From 40907b163690ec9bd8ad73248f75785eb15e7588 Mon Sep 17 00:00:00 2001 From: Scorpiokat Date: Tue, 3 Jan 2017 14:55:12 +0000 Subject: [PATCH 2/4] This commit fixes #803 --- ShellCheck/Analytics.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f1be786..495785f 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -358,7 +358,7 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do let flagsGrep = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep flagsWc = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand wc in - unless ((any (`elem` ["o", "only-matching"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ + unless ((any (`elem` ["o", "only-matching", "r", "R", "recursive"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." didLs <- liftM or . sequence $ [ From daacc98a8f2ea92cbef565d52a2e89a88caeb769 Mon Sep 17 00:00:00 2001 From: Ekaterina Efimova Date: Tue, 3 Jan 2017 21:40:32 +0300 Subject: [PATCH 3/4] Update Analytics.hs --- ShellCheck/Analytics.hs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 495785f..f1be786 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -358,7 +358,7 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do let flagsGrep = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep flagsWc = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand wc in - unless ((any (`elem` ["o", "only-matching", "r", "R", "recursive"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ + unless ((any (`elem` ["o", "only-matching"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." didLs <- liftM or . sequence $ [ From 43f667a8f910e24500d66c4fabce64e6856080c6 Mon Sep 17 00:00:00 2001 From: Ekaterina Efimova Date: Tue, 3 Jan 2017 21:48:35 +0300 Subject: [PATCH 4/4] Update Analytics.hs --- ShellCheck/Analytics.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f1be786..77a9e1c 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -334,6 +334,7 @@ prop_checkPipePitfalls12 = verifyNot checkPipePitfalls "foo | grep -o bar | wc - prop_checkPipePitfalls13 = verifyNot checkPipePitfalls "foo | grep bar | wc -c" prop_checkPipePitfalls14 = verifyNot checkPipePitfalls "foo | grep -o bar | wc -cmwL" prop_checkPipePitfalls15 = verifyNot checkPipePitfalls "foo | grep bar | wc -cmwL" +prop_checkPipePitfalls16 = verifyNot checkPipePitfalls "foo | grep -r bar | wc -l" checkPipePitfalls _ (T_Pipeline id _ commands) = do for ["find", "xargs"] $ \(find:xargs:_) -> @@ -358,7 +359,7 @@ checkPipePitfalls _ (T_Pipeline id _ commands) = do let flagsGrep = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand grep flagsWc = fromMaybe [] $ map snd <$> getAllFlags <$> getCommand wc in - unless ((any (`elem` ["o", "only-matching"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ + unless ((any (`elem` ["o", "only-matching", "r", "R", "recursive"]) flagsGrep) || (any (`elem` ["m", "chars", "w", "words", "c", "bytes", "L", "max-line-length"]) flagsWc) || ((length flagsWc) == 0)) $ style (getId grep) 2126 "Consider using grep -c instead of grep|wc -l." didLs <- liftM or . sequence $ [