From a8715d2d5fb46ae19db1c6216c57353a37640844 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Tue, 27 Nov 2012 00:41:10 -0800 Subject: [PATCH] Added check for A=foo | grep bar --- ShellCheck/Analytics.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index ba33031..419f6f8 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -64,6 +64,7 @@ basicChecks = [ ,checkEcho ,checkConstantIfs ,checkTrAZ + ,checkPipedAssignment ] modifyMap = modify @@ -135,6 +136,15 @@ checkEcho (T_Pipeline id [a, b]) = checkEcho _ = return () checkEchoSedRe = mkRegex "^s(.)(.*)\\1(.*)\\1g?$" + +prop_checkPipedAssignment1 = verify checkPipedAssignment "A=ls | grep foo" +prop_checkPipedAssignment2 = verifyNot checkPipedAssignment "A=foo cmd | grep foo" +prop_checkPipedAssignment3 = verifyNot checkPipedAssignment "A=foo" +checkPipedAssignment (T_Pipeline _ (T_Redirecting _ _ (T_SimpleCommand id (_:_) []):_:_)) = + warn id "If you wanted to assign the output of the pipeline, use a=$(b | c)" +checkPipedAssignment _ = return () + + prop_checkUuoc = verify checkUuoc "cat foo | grep bar" checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) = case deadSimple f of ["cat", _] -> style id "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead."