mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-08-07 20:52:45 +08:00
Added warning for a && b || c
This commit is contained in:
@@ -19,7 +19,8 @@ basicChecks = [
|
||||
checkForInLs,
|
||||
checkMissingForQuotes,
|
||||
checkUnquotedExpansions,
|
||||
checkRedirectToSame
|
||||
checkRedirectToSame,
|
||||
checkShorthandIf
|
||||
]
|
||||
|
||||
modifyMap = modify
|
||||
@@ -128,4 +129,10 @@ checkRedirectToSame s@(T_Pipeline _ list) =
|
||||
checkRedirectToSame _ = return ()
|
||||
|
||||
|
||||
prop_checkShorthandIf = verify checkShorthandIf "[[ ! -z file ]] && scp file host || rm file"
|
||||
prop_checkShorthandIf2 = verifyNot checkShorthandIf "[[ ! -z file ]] && { scp file host || echo 'Eek'; }"
|
||||
checkShorthandIf (T_AndIf id _ (T_OrIf _ _ _)) =
|
||||
addNoteFor id $ Note InfoC "Note that A && B || C is not if-then-else. C may run when A is true."
|
||||
checkShorthandIf _ = return ()
|
||||
|
||||
lt x = trace (show x) x
|
||||
|
2
badcase/poormansif
Normal file
2
badcase/poormansif
Normal file
@@ -0,0 +1,2 @@
|
||||
# When the network goes down, the backup gets deleted
|
||||
[[ ! -z backup ]] && scp backup host: || rm backup
|
Reference in New Issue
Block a user