From 4f1fd433607d26dd660e4115a600b40a0b2f7424 Mon Sep 17 00:00:00 2001 From: Vidar Holen Date: Sun, 16 Mar 2014 15:06:18 -0700 Subject: [PATCH] Don't suggest removing $ in (( 10#$n )) --- ShellCheck/Analytics.hs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/ShellCheck/Analytics.hs b/ShellCheck/Analytics.hs index f9366ab..bc5dc65 100644 --- a/ShellCheck/Analytics.hs +++ b/ShellCheck/Analytics.hs @@ -998,9 +998,14 @@ prop_checkArithmeticDeref3 = verifyNot checkArithmeticDeref "cow=1/40; (( s+= ${ prop_checkArithmeticDeref4 = verifyNot checkArithmeticDeref "(( ! $? ))" prop_checkArithmeticDeref5 = verifyNot checkArithmeticDeref "(($1))" prop_checkArithmeticDeref6 = verifyNot checkArithmeticDeref "(( ${a[$i]} ))" -checkArithmeticDeref _ (TA_Expansion _ (T_DollarBraced id l)) | not . excepting $ bracedString l = - style id 2004 $ "Don't use $ on variables in (( ))." +prop_checkArithmeticDeref7 = verifyNot checkArithmeticDeref "(( 10#$n ))" +checkArithmeticDeref params t@(TA_Expansion _ (T_DollarBraced id l)) = + when (not $ (excepting $ bracedString l) || inBaseExpression) $ + style id 2004 $ "$ on variables in (( )) is unnecessary." where + inBaseExpression = any isBase $ parents params t + isBase (TA_Base {}) = True + isBase _ = False excepting [] = True excepting s = (any (`elem` "/.:#%?*@[]") s) || (isDigit $ head s) checkArithmeticDeref _ _ = return () @@ -1139,6 +1144,8 @@ getPath tree t = t : Nothing -> [] Just parent -> getPath tree parent +parents params t = getPath (parentMap params) t + --- Command specific checks checkCommand str f t@(T_SimpleCommand id _ (cmd:rest)) =