From 69183f6609c907e48eb8df52e9a43241355e881d Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 4 Nov 2012 22:14:47 -0800 Subject: [PATCH] Added warning for a && b || c --- Shpell/Analytics.hs | 9 ++++++++- badcase/poormansif | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 badcase/poormansif diff --git a/Shpell/Analytics.hs b/Shpell/Analytics.hs index d2cd8ff..57a0ce1 100644 --- a/Shpell/Analytics.hs +++ b/Shpell/Analytics.hs @@ -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 diff --git a/badcase/poormansif b/badcase/poormansif new file mode 100644 index 0000000..1dae836 --- /dev/null +++ b/badcase/poormansif @@ -0,0 +1,2 @@ +# When the network goes down, the backup gets deleted +[[ ! -z backup ]] && scp backup host: || rm backup