From 73c6202842321dc4be9d0afe812ee06c47493817 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Thu, 4 Jul 2013 14:27:03 -0700 Subject: [PATCH] Fixed misplaced uuoc for 'cat foo' outside pipe. --- ShellCheck/Analytics.hs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 92c383e..90fd8d4 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -273,7 +273,8 @@ checkAssignAteCommand _ = return () prop_checkUuoc1 = verify checkUuoc "cat foo | grep bar" prop_checkUuoc2 = verifyNot checkUuoc "cat * | grep bar" prop_checkUuoc3 = verify checkUuoc "cat $var | grep bar" -checkUuoc = checkCommand "cat" f +prop_checkUuoc4 = verifyNot checkUuoc "cat $var" +checkUuoc (T_Pipeline _ ((T_Redirecting _ _ cmd):_:_)) = checkCommand "cat" f cmd where f [word] = when (isSimple word) $ style (getId word) "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead." @@ -281,6 +282,7 @@ checkUuoc = checkCommand "cat" f isSimple (T_NormalWord _ parts) = all isSimple parts isSimple (T_DollarBraced _ _) = True isSimple x = not $ willSplit x +checkUuoc _ = return () prop_checkNeedlessCommands = verify checkNeedlessCommands "foo=$(expr 3 + 2)" checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "expr" = @@ -1418,8 +1420,8 @@ checkSpacefulness t = readF _ token name = do spaced <- hasSpaces name - if spaced - && (not $ inUnquotableContext parents token) + if spaced + && (not $ inUnquotableContext parents token) && (not $ usedAsCommandName parents token) then return [(getId token, Note InfoC warning)] else return []