From eecd003e2db0776ed989c0f04df9bfba75689d11 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Tue, 11 Feb 2020 01:04:49 -0500 Subject: [PATCH] Optimize patterns in checkFindNameGlob 1. Instead of pattern-matching the same list multiple times, do it only once and then pass the pieces separately. 2. Don't reconstruct an object equivalent to one we just deconstructed. --- src/ShellCheck/Checks/Commands.hs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index f8f3a20..e321102 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -199,11 +199,12 @@ prop_checkFindNameGlob3 = verifyNot checkFindNameGlob "find * -name '*.php'" checkFindNameGlob = CommandCheck (Basename "find") (f . arguments) where acceptsGlob s = s `elem` [ "-ilname", "-iname", "-ipath", "-iregex", "-iwholename", "-lname", "-name", "-path", "-regex", "-wholename" ] f [] = return () - f [x] = return () - f (a:b:r) = do + f (x:xs) = g x xs + g _ [] = return () + g a (b:r) = do forM_ (getLiteralString a) $ \s -> when (acceptsGlob s && isGlob b) $ warn (getId b) 2061 $ "Quote the parameter to " ++ s ++ " so the shell won't interpret it." - f (b:r) + g b r prop_checkNeedlessExpr = verify checkNeedlessExpr "foo=$(expr 3 + 2)"