From e8fc09414a92884cf9fbf9de758f210a5ea6f411 Mon Sep 17 00:00:00 2001 From: Jon Higgs Date: Thu, 22 Feb 2018 15:51:48 +1100 Subject: [PATCH] Check for calls to `which`. Favour the builtin `command -v` instead. --- ShellCheck/Checks/Commands.hs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ShellCheck/Checks/Commands.hs b/ShellCheck/Checks/Commands.hs index 5ecc8cc..bef491d 100644 --- a/ShellCheck/Checks/Commands.hs +++ b/ShellCheck/Checks/Commands.hs @@ -91,6 +91,7 @@ commandChecks = [ ,checkMvArguments, checkCpArguments, checkLnArguments ,checkFindRedirections ,checkReadExpansions + ,checkWhich ] buildCommandMap :: [CommandCheck] -> Map.Map CommandName (Token -> Analysis) @@ -939,6 +940,9 @@ checkFindRedirections = CommandCheck (Basename "find") f "Redirection applies to the find command itself. Rewrite to work per action (or move to end)." _ -> return () +prop_checkWhich = verify checkWhich "which '.+'" +checkWhich = CommandCheck (Basename "which") $ + \t -> info (getId t) 2230 "which is non-standard. Use builtin 'command -v' instead." return [] runTests = $( [| $(forAllProperties) (quickCheckWithResult (stdArgs { maxSuccess = 1 }) ) |])