From cc424bac11864e5c445b18490e0507457b86b5a5 Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 9 Feb 2020 19:40:57 -0500 Subject: [PATCH] Use find instead of take 1 and filter --- src/ShellCheck/Analytics.hs | 6 +++--- src/ShellCheck/Checks/Commands.hs | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index e91810b..fa640b1 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -790,7 +790,7 @@ prop_checkUnquotedDollarAt8 = verifyNot checkUnquotedDollarAt "echo \"${args[@]: prop_checkUnquotedDollarAt9 = verifyNot checkUnquotedDollarAt "echo ${args[@]:+\"${args[@]}\"}" prop_checkUnquotedDollarAt10 = verifyNot checkUnquotedDollarAt "echo ${@+\"$@\"}" 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) $ err (getId x) 2068 "Double quote array expansions to avoid re-splitting elements." @@ -807,7 +807,7 @@ checkConcatenatedDollarAt p word@T_NormalWord {} mapM_ for array where 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." 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." checkStrings = - mapM_ stringError . take 1 . filter isNonNum + mapM_ stringError . find isNonNum isNonNum t = fromMaybe False $ do s <- getLiteralStringExt (const $ return "") t diff --git a/src/ShellCheck/Checks/Commands.hs b/src/ShellCheck/Checks/Commands.hs index 299a335..881dd9d 100644 --- a/src/ShellCheck/Checks/Commands.hs +++ b/src/ShellCheck/Checks/Commands.hs @@ -748,7 +748,7 @@ checkAliasesExpandEarly = CommandCheck (Exactly "alias") (f . arguments) where f = mapM_ checkArg 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." checkArg _ = return ()