mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-13 16:43:20 -07:00
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.
This commit is contained in:
parent
440d0038aa
commit
eecd003e2d
1 changed files with 4 additions and 3 deletions
|
@ -199,11 +199,12 @@ prop_checkFindNameGlob3 = verifyNot checkFindNameGlob "find * -name '*.php'"
|
||||||
checkFindNameGlob = CommandCheck (Basename "find") (f . arguments) where
|
checkFindNameGlob = CommandCheck (Basename "find") (f . arguments) where
|
||||||
acceptsGlob s = s `elem` [ "-ilname", "-iname", "-ipath", "-iregex", "-iwholename", "-lname", "-name", "-path", "-regex", "-wholename" ]
|
acceptsGlob s = s `elem` [ "-ilname", "-iname", "-ipath", "-iregex", "-iwholename", "-lname", "-name", "-path", "-regex", "-wholename" ]
|
||||||
f [] = return ()
|
f [] = return ()
|
||||||
f [x] = return ()
|
f (x:xs) = g x xs
|
||||||
f (a:b:r) = do
|
g _ [] = return ()
|
||||||
|
g a (b:r) = do
|
||||||
forM_ (getLiteralString a) $ \s -> when (acceptsGlob s && isGlob b) $
|
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."
|
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)"
|
prop_checkNeedlessExpr = verify checkNeedlessExpr "foo=$(expr 3 + 2)"
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue