From 3fc77d94ec95db73091e0e55769f4ea51f4749c7 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Mon, 28 Sep 2015 18:46:32 -0700 Subject: [PATCH] Warn about [ -n foo ] when foo is entirely constant. --- ShellCheck/Analytics.hs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 9254dd2..83c2139 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -1249,13 +1249,13 @@ prop_checkLiteralBreakingTest5 = verify checkLiteralBreakingTest "[ -n \"$(true) prop_checkLiteralBreakingTest6 = verify checkLiteralBreakingTest "[ -z $(true)z ]" prop_checkLiteralBreakingTest7 = verifyNot checkLiteralBreakingTest "[ -z $(true) ]" prop_checkLiteralBreakingTest8 = verifyNot checkLiteralBreakingTest "[ $(true)$(true) ]" +prop_checkLiteralBreakingTest10 = verify checkLiteralBreakingTest "[ -z foo ]" checkLiteralBreakingTest _ t = potentially $ case t of (TC_Noary _ _ w@(T_NormalWord _ l)) -> do - guard . not $ isConstant w + guard . not $ isConstant w -- Covered by SC2078 comparisonWarning l `mplus` tautologyWarning w "Argument to implicit -n is always true due to literal strings." - (TC_Unary _ _ op w@(T_NormalWord _ l)) -> do - guard $ not $ isConstant w + (TC_Unary _ _ op w@(T_NormalWord _ l)) -> case op of "-n" -> tautologyWarning w "Argument to -n is always true due to literal strings." "-z" -> tautologyWarning w "Argument to -z is always false due to literal strings."