Fixed UUOC warning for 'cat * | ..'.

This commit is contained in:
Vidar Holen 2013-07-04 12:26:59 -07:00
parent ab20747ef2
commit d2c5802a9d

View file

@ -267,11 +267,17 @@ checkAssignAteCommand (T_SimpleCommand id ((T_Assignment _ _ assignmentTerm):[])
checkAssignAteCommand _ = return () checkAssignAteCommand _ = return ()
prop_checkUuoc = verify checkUuoc "cat foo | grep bar" prop_checkUuoc1 = verify checkUuoc "cat foo | grep bar"
checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) = prop_checkUuoc2 = verifyNot checkUuoc "cat * | grep bar"
case deadSimple f of ["cat", _] -> style id "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead." prop_checkUuoc3 = verify checkUuoc "cat $var | grep bar"
_ -> return () checkUuoc = checkCommand "cat" f
checkUuoc _ = return () where
f [word] = when (isSimple word) $
style (getId word) "Useless cat. Consider 'cmd < file | ..' or 'cmd file | ..' instead."
f _ = return ()
isSimple (T_NormalWord _ parts) = all isSimple parts
isSimple (T_DollarBraced _ _) = True
isSimple x = not $ willSplit x
prop_checkNeedlessCommands = verify checkNeedlessCommands "foo=$(expr 3 + 2)" prop_checkNeedlessCommands = verify checkNeedlessCommands "foo=$(expr 3 + 2)"
checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "expr" = checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "expr" =