From 868d53af95855d957193d4be6bff2f3b2989ae82 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sat, 24 Sep 2016 14:49:52 -0700 Subject: [PATCH] Warn about passing globs to `unset`. --- ShellCheck/Checks/Commands.hs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/ShellCheck/Checks/Commands.hs b/ShellCheck/Checks/Commands.hs index e9964e0..21a309e 100644 --- a/ShellCheck/Checks/Commands.hs +++ b/ShellCheck/Checks/Commands.hs @@ -90,6 +90,7 @@ commandChecks = [ ,checkExportedExpansions ,checkAliasesUsesArgs ,checkAliasesExpandEarly + ,checkUnsetGlobs ] buildCommandMap :: [CommandCheck] -> Map.Map CommandName (Token -> Analysis) @@ -589,5 +590,14 @@ checkAliasesExpandEarly = CommandCheck (Exactly "alias") (f . arguments) checkArg _ = return () +prop_checkUnsetGlobs1 = verify checkUnsetGlobs "unset foo[1]" +prop_checkUnsetGlobs2 = verifyNot checkUnsetGlobs "unset foo" +checkUnsetGlobs = CommandCheck (Exactly "unset") (mapM_ check . arguments) + where + check arg = + when (isGlob arg) $ + warn (getId arg) 2184 "Quote arguments to unset so they're not glob expanded." + + return [] runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])