From b7f88ec4b72bae672f1b77e4af312990f17ab86b Mon Sep 17 00:00:00 2001 From: "Joseph C. Sible" Date: Sun, 31 Dec 2023 18:09:02 -0500 Subject: [PATCH] Stop building tuples that we never look at both sides of --- src/ShellCheck/Analytics.hs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/ShellCheck/Analytics.hs b/src/ShellCheck/Analytics.hs index 3f686ee..9913b09 100644 --- a/src/ShellCheck/Analytics.hs +++ b/src/ShellCheck/Analytics.hs @@ -4819,15 +4819,15 @@ checkExtraMaskedReturns params t = ++ "separately to avoid masking its return value (or use '|| true' " ++ "to ignore).") - isMaskDeliberate t = hasParent isOrIf t + isMaskDeliberate t = any isOrIf $ NE.init $ parents params t where - isOrIf _ (T_OrIf _ _ (T_Pipeline _ _ [T_Redirecting _ _ cmd])) + isOrIf (T_OrIf _ _ (T_Pipeline _ _ [T_Redirecting _ _ cmd])) = getCommandBasename cmd `elem` [Just "true", Just ":"] - isOrIf _ _ = False + isOrIf _ = False - isCheckedElsewhere t = hasParent isDeclaringCommand t + isCheckedElsewhere t = any isDeclaringCommand $ NE.tail $ parents params t where - isDeclaringCommand t _ = fromMaybe False $ do + isDeclaringCommand t = fromMaybe False $ do cmd <- getCommand t basename <- getCommandBasename cmd return $ @@ -4851,13 +4851,6 @@ checkExtraMaskedReturns params t = basename <- getCommandBasename t return $ basename == "time" - parentChildPairs t = go $ NE.toList $ parents params t - where - go (child:parent:rest) = (parent, child):go (parent:rest) - go _ = [] - - hasParent pred t = any (uncurry pred) (parentChildPairs t) - -- hard error on negated command that is not last prop_checkBatsTestDoesNotUseNegation1 = verify checkBatsTestDoesNotUseNegation "#!/usr/bin/env/bats\n@test \"name\" { ! true; false; }"