Don't warn about a&&b||c if c == printf

This commit is contained in:
Vidar Holen 2015-05-24 12:41:54 -07:00
parent 828378cdff
commit 3a041954d1
1 changed files with 2 additions and 1 deletions

View File

@ -916,13 +916,14 @@ prop_checkShorthandIf = verify checkShorthandIf "[[ ! -z file ]] && scp file ho
prop_checkShorthandIf2 = verifyNot checkShorthandIf "[[ ! -z file ]] && { scp file host || echo 'Eek'; }"
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 =
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"])
return $ name `elem` ["echo", "exit", "return", "printf"])
isOk _ = False
checkShorthandIf _ _ = return ()