From d406ba9950fad6bd03928cafe2fd667ae80be315 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 18 Jul 2015 11:47:28 -0700 Subject: [PATCH] Special case messages for [ true ] and false/0/1 --- ShellCheck/Analytics.hs | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 28a597e..d18463b 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -1321,8 +1321,19 @@ prop_checkConstantNoary = verify checkConstantNoary "[[ '$(foo)' ]]" prop_checkConstantNoary2 = verify checkConstantNoary "[ \"-f lol\" ]" prop_checkConstantNoary3 = verify checkConstantNoary "[[ cmd ]]" prop_checkConstantNoary4 = verify checkConstantNoary "[[ ! cmd ]]" +prop_checkConstantNoary5 = verify checkConstantNoary "[[ true ]]" +prop_checkConstantNoary6 = verify checkConstantNoary "[ 1 ]" +prop_checkConstantNoary7 = verify checkConstantNoary "[ false ]" checkConstantNoary _ (TC_Noary _ _ t) | isConstant t = - err (getId t) 2078 "This expression is constant. Did you forget a $ somewhere?" + case fromMaybe "" $ getLiteralString t of + "false" -> err (getId t) 2158 "[ false ] is true. Remove the brackets." + "0" -> err (getId t) 2159 "[ 0 ] is true. Use 'false' instead." + "true" -> style (getId t) 2160 "Instead of '[ true ]', just use 'true'." + "1" -> style (getId t) 2161 "Instead of '[ 1 ]', use 'true'." + _ -> err (getId t) 2078 "This expression is constant. Did you forget a $ somewhere?" + where + string = fromMaybe "" $ getLiteralString t + checkConstantNoary _ _ = return () prop_checkBraceExpansionVars1 = verify checkBraceExpansionVars "echo {1..$n}"