From 3308ac917386c767bb0dfaa32e88a43927897f46 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Wed, 28 Nov 2012 21:06:58 -0800 Subject: [PATCH] Warning for dirname/basename --- ShellCheck/Analytics.hs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index 39c0c16..22581e5 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -70,7 +70,7 @@ basicChecks = [ ,checkFindNameGlob ,checkGrepRe ,checkDollarArithmeticCommand - ,checkExpr + ,checkNeedlessCommands ,checkQuotedCondRegex ,checkForInCat ] @@ -180,10 +180,14 @@ checkUuoc (T_Pipeline _ (T_Redirecting _ _ f@(T_SimpleCommand id _ _):_:_)) = _ -> return () checkUuoc _ = return () -prop_checkExpr = verify checkExpr "foo=$(expr 3 + 2)" -checkExpr (T_SimpleCommand id _ (w:_)) | w `isCommand` "expr" = +prop_checkNeedlessCommands = verify checkNeedlessCommands "foo=$(expr 3 + 2)" +checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "expr" = style id "Use $((..)), ${} or [[ ]] in place of antiquated expr." -checkExpr _ = return () +checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "dirname" = + style id "Use parameter expansion instead, such as ${var%/*}." +checkNeedlessCommands (T_SimpleCommand id _ (w:_)) | w `isCommand` "basename" = + style id "Use parameter expansion instead, such as ${var##*/}." +checkNeedlessCommands _ = return () prop_checkPipePitfalls1 = verify checkPipePitfalls "foo | grep foo | awk bar" prop_checkPipePitfalls2 = verifyNot checkPipePitfalls "foo | awk bar | grep foo"