From 889433355661b8866155382227074983c052415b Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 18 Jul 2015 13:23:36 -0700 Subject: [PATCH] Warn about 'export $foo' --- ShellCheck/Analytics.hs | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 6eb5c67..64e9576 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -207,6 +207,7 @@ nodeChecks = [ ,checkMaskedReturns ,checkInjectableFindSh ,checkReadWithoutR + ,checkExportedExpansions ] @@ -3461,6 +3462,18 @@ checkReadWithoutR _ t@(T_SimpleCommand {}) | t `isUnqualifiedCommand` "read" = info (getId t) 2162 "read without -r will mangle backslashes." checkReadWithoutR _ _ = return () +prop_checkExportedExpansions1 = verify checkExportedExpansions "export $foo" +prop_checkExportedExpansions2 = verify checkExportedExpansions "export \"$foo\"" +prop_checkExportedExpansions3 = verifyNot checkExportedExpansions "export foo" +checkExportedExpansions _ = checkUnqualifiedCommand "export" (const check) + where + check = mapM_ checkForVariables + checkForVariables f = + case getWordParts f of + [t@(T_DollarBraced {})] -> + warn (getId t) 2163 "Exporting an expansion rather than a variable." + _ -> return () + return [] runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |]) -- GitLab