Use find instead of take 1 and filter

This commit is contained in:
Joseph C. Sible 2020-02-09 19:40:57 -05:00
parent cb01cbf7eb
commit cc424bac11
2 changed files with 4 additions and 4 deletions

View File

@ -790,7 +790,7 @@ prop_checkUnquotedDollarAt8 = verifyNot checkUnquotedDollarAt "echo \"${args[@]:
prop_checkUnquotedDollarAt9 = verifyNot checkUnquotedDollarAt "echo ${args[@]:+\"${args[@]}\"}" prop_checkUnquotedDollarAt9 = verifyNot checkUnquotedDollarAt "echo ${args[@]:+\"${args[@]}\"}"
prop_checkUnquotedDollarAt10 = verifyNot checkUnquotedDollarAt "echo ${@+\"$@\"}" prop_checkUnquotedDollarAt10 = verifyNot checkUnquotedDollarAt "echo ${@+\"$@\"}"
checkUnquotedDollarAt p word@(T_NormalWord _ parts) | not $ isStrictlyQuoteFree (parentMap p) word = checkUnquotedDollarAt p word@(T_NormalWord _ parts) | not $ isStrictlyQuoteFree (parentMap p) word =
forM_ (take 1 $ filter isArrayExpansion parts) $ \x -> forM_ (find isArrayExpansion parts) $ \x ->
unless (isQuotedAlternativeReference x) $ unless (isQuotedAlternativeReference x) $
err (getId x) 2068 err (getId x) 2068
"Double quote array expansions to avoid re-splitting elements." "Double quote array expansions to avoid re-splitting elements."
@ -807,7 +807,7 @@ checkConcatenatedDollarAt p word@T_NormalWord {}
mapM_ for array mapM_ for array
where where
parts = getWordParts word parts = getWordParts word
array = take 1 $ filter isArrayExpansion parts array = find isArrayExpansion parts
for t = err (getId t) 2145 "Argument mixes string and array. Use * or separate argument." for t = err (getId t) 2145 "Argument mixes string and array. Use * or separate argument."
checkConcatenatedDollarAt _ _ = return () checkConcatenatedDollarAt _ _ = return ()
@ -1059,7 +1059,7 @@ checkNumberComparisons params (TC_Binary id typ op lhs rhs) = do
"Either use integers only, or use bc or awk to compare." "Either use integers only, or use bc or awk to compare."
checkStrings = checkStrings =
mapM_ stringError . take 1 . filter isNonNum mapM_ stringError . find isNonNum
isNonNum t = fromMaybe False $ do isNonNum t = fromMaybe False $ do
s <- getLiteralStringExt (const $ return "") t s <- getLiteralStringExt (const $ return "") t

View File

@ -748,7 +748,7 @@ checkAliasesExpandEarly = CommandCheck (Exactly "alias") (f . arguments)
where where
f = mapM_ checkArg f = mapM_ checkArg
checkArg arg | '=' `elem` concat (oversimplify arg) = checkArg arg | '=' `elem` concat (oversimplify arg) =
forM_ (take 1 $ filter (not . isLiteral) $ getWordParts arg) $ forM_ (find (not . isLiteral) $ getWordParts arg) $
\x -> warn (getId x) 2139 "This expands when defined, not when used. Consider escaping." \x -> warn (getId x) 2139 "This expands when defined, not when used. Consider escaping."
checkArg _ = return () checkArg _ = return ()