From 1d04754b37acf8237fb737adbc7e007ff980e366 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 14 May 2016 17:14:32 -0700 Subject: [PATCH] Don't warn about a && b || c in if/while/until. --- ShellCheck/Analytics.hs | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 3b62142..634ab1c 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -831,14 +831,18 @@ prop_checkShorthandIf2 = verifyNot checkShorthandIf "[[ ! -z file ]] && { scp fi prop_checkShorthandIf3 = verifyNot checkShorthandIf "foo && bar || echo baz" prop_checkShorthandIf4 = verifyNot checkShorthandIf "foo && a=b || a=c" prop_checkShorthandIf5 = verifyNot checkShorthandIf "foo && rm || printf b" -checkShorthandIf _ (T_AndIf id _ (T_OrIf _ _ (T_Pipeline _ _ t))) - | not $ isOk t = +prop_checkShorthandIf6 = verifyNot checkShorthandIf "if foo && bar || baz; then true; fi" +prop_checkShorthandIf7 = verifyNot checkShorthandIf "while foo && bar || baz; do true; done" +prop_checkShorthandIf8 = verify checkShorthandIf "if true; then foo && bar || baz; fi" +checkShorthandIf params x@(T_AndIf id _ (T_OrIf _ _ (T_Pipeline _ _ t))) + | not (isOk t || inCondition) = info id 2015 "Note that A && B || C is not if-then-else. C may run when A is true." where isOk [t] = isAssignment t || fromMaybe False (do name <- getCommandBasename t return $ name `elem` ["echo", "exit", "return", "printf"]) isOk _ = False + inCondition = isCondition $ getPath (parentMap params) x checkShorthandIf _ _ = return ()