diff options
author | Vidar Holen <spam@vidarholen.net> | 2016-05-14 17:14:32 -0700 |
---|---|---|
committer | Vidar Holen <spam@vidarholen.net> | 2016-05-14 17:14:32 -0700 |
commit | 1d04754b37acf8237fb737adbc7e007ff980e366 (patch) | |
tree | 42b8342b1131eaf5bee378112d1bb2da4c207680 | |
parent | 13ff0a74328d7be12345fc44b79a1a0f2832be8e (diff) |
Don't warn about a && b || c in if/while/until.
-rw-r--r-- | ShellCheck/Analytics.hs | 8 |
1 files 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 () |