From 7aa3a7ffc33f630b6838078dc37e73ed27d581b0 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 17 Feb 2018 17:08:32 -0800 Subject: [PATCH] Improve message for SC2163 (export $var). Helps #1117 --- ShellCheck/Checks/Commands.hs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Checks/Commands.hs b/ShellCheck/Checks/Commands.hs index b7b625c..161fb4b 100644 --- a/ShellCheck/Checks/Commands.hs +++ b/ShellCheck/Checks/Commands.hs @@ -587,13 +587,18 @@ checkSetAssignment = CommandCheck (Exactly "set") (f . arguments) prop_checkExportedExpansions1 = verify checkExportedExpansions "export $foo" prop_checkExportedExpansions2 = verify checkExportedExpansions "export \"$foo\"" prop_checkExportedExpansions3 = verifyNot checkExportedExpansions "export foo" +prop_checkExportedExpansions4 = verifyNot checkExportedExpansions "export ${foo?}" checkExportedExpansions = CommandCheck (Exactly "export") (check . arguments) where check = mapM_ checkForVariables checkForVariables f = case getWordParts f of - [t@(T_DollarBraced {})] -> - warn (getId t) 2163 "Exporting an expansion rather than a variable." + [t@(T_DollarBraced {})] -> potentially $ do + let contents = bracedString t + let name = getBracedReference contents + guard $ name == contents + return . warn (getId t) 2163 $ + "This does not export '" ++ name ++ "'. Remove $/${} for that, or use ${var?} to quiet." _ -> return () -- GitLab