Auto-disable SC2119 when disabling SC2120 (fixes #703)
This commit is contained in:
parent
301705edea
commit
bf1003eae3
|
@ -15,6 +15,7 @@
|
||||||
### Changed
|
### Changed
|
||||||
- If a directive or shebang is not specified, a `.bash/.bats/.dash/.ksh`
|
- If a directive or shebang is not specified, a `.bash/.bats/.dash/.ksh`
|
||||||
extension will be used to infer the shell type when present.
|
extension will be used to infer the shell type when present.
|
||||||
|
- Disabling SC2120 on a function now disables SC2119 on call sites
|
||||||
|
|
||||||
## v0.6.0 - 2018-12-02
|
## v0.6.0 - 2018-12-02
|
||||||
### Added
|
### Added
|
||||||
|
|
|
@ -501,3 +501,13 @@ isCommandSubstitution t = case t of
|
||||||
T_DollarBraceCommandExpansion {} -> True
|
T_DollarBraceCommandExpansion {} -> True
|
||||||
T_Backticked {} -> True
|
T_Backticked {} -> True
|
||||||
_ -> False
|
_ -> False
|
||||||
|
|
||||||
|
|
||||||
|
-- Is this a T_Annotation that ignores a specific code?
|
||||||
|
isAnnotationIgnoringCode code t =
|
||||||
|
case t of
|
||||||
|
T_Annotation _ anns _ -> any hasNum anns
|
||||||
|
_ -> False
|
||||||
|
where
|
||||||
|
hasNum (DisableComment ts) = code == ts
|
||||||
|
hasNum _ = False
|
||||||
|
|
|
@ -2304,6 +2304,7 @@ prop_checkUnpassedInFunctions9 = verifyNotTree checkUnpassedInFunctions "foo() {
|
||||||
prop_checkUnpassedInFunctions10= verifyNotTree checkUnpassedInFunctions "foo() { echo $!; }; foo;"
|
prop_checkUnpassedInFunctions10= verifyNotTree checkUnpassedInFunctions "foo() { echo $!; }; foo;"
|
||||||
prop_checkUnpassedInFunctions11= verifyNotTree checkUnpassedInFunctions "foo() { bar() { echo $1; }; bar baz; }; foo;"
|
prop_checkUnpassedInFunctions11= verifyNotTree checkUnpassedInFunctions "foo() { bar() { echo $1; }; bar baz; }; foo;"
|
||||||
prop_checkUnpassedInFunctions12= verifyNotTree checkUnpassedInFunctions "foo() { echo ${!var*}; }; foo;"
|
prop_checkUnpassedInFunctions12= verifyNotTree checkUnpassedInFunctions "foo() { echo ${!var*}; }; foo;"
|
||||||
|
prop_checkUnpassedInFunctions13= verifyNotTree checkUnpassedInFunctions "# shellcheck disable=SC2120\nfoo() { echo $1; }\nfoo\n"
|
||||||
checkUnpassedInFunctions params root =
|
checkUnpassedInFunctions params root =
|
||||||
execWriter $ mapM_ warnForGroup referenceGroups
|
execWriter $ mapM_ warnForGroup referenceGroups
|
||||||
where
|
where
|
||||||
|
@ -2355,17 +2356,24 @@ checkUnpassedInFunctions params root =
|
||||||
updateWith x@(name, _, _) = Map.insertWith (++) name [x]
|
updateWith x@(name, _, _) = Map.insertWith (++) name [x]
|
||||||
|
|
||||||
warnForGroup group =
|
warnForGroup group =
|
||||||
when (all isArgumentless group) $ do
|
when (all isArgumentless group) $
|
||||||
mapM_ suggestParams group
|
-- Allow ignoring SC2120 on the function to ignore all calls
|
||||||
warnForDeclaration group
|
let (name, func) = getFunction group
|
||||||
|
ignoring = shouldIgnoreCode params 2120 func
|
||||||
|
in unless ignoring $ do
|
||||||
|
mapM_ suggestParams group
|
||||||
|
warnForDeclaration func name
|
||||||
|
|
||||||
suggestParams (name, _, thing) =
|
suggestParams (name, _, thing) =
|
||||||
info (getId thing) 2119 $
|
info (getId thing) 2119 $
|
||||||
"Use " ++ name ++ " \"$@\" if function's $1 should mean script's $1."
|
"Use " ++ name ++ " \"$@\" if function's $1 should mean script's $1."
|
||||||
warnForDeclaration ((name, _, _):_) =
|
warnForDeclaration func name =
|
||||||
warn (getId . fromJust $ Map.lookup name functionMap) 2120 $
|
warn (getId func) 2120 $
|
||||||
name ++ " references arguments, but none are ever passed."
|
name ++ " references arguments, but none are ever passed."
|
||||||
|
|
||||||
|
getFunction ((name, _, _):_) =
|
||||||
|
(name, fromJust $ Map.lookup name functionMap)
|
||||||
|
|
||||||
|
|
||||||
prop_checkOverridingPath1 = verify checkOverridingPath "PATH=\"$var/$foo\""
|
prop_checkOverridingPath1 = verify checkOverridingPath "PATH=\"$var/$foo\""
|
||||||
prop_checkOverridingPath2 = verify checkOverridingPath "PATH=\"mydir\""
|
prop_checkOverridingPath2 = verify checkOverridingPath "PATH=\"mydir\""
|
||||||
|
|
|
@ -882,16 +882,15 @@ filterByAnnotation asSpec params =
|
||||||
shouldIgnore note =
|
shouldIgnore note =
|
||||||
any (shouldIgnoreFor (getCode note)) $
|
any (shouldIgnoreFor (getCode note)) $
|
||||||
getPath parents (T_Bang $ tcId note)
|
getPath parents (T_Bang $ tcId note)
|
||||||
shouldIgnoreFor num (T_Annotation _ anns _) =
|
|
||||||
any hasNum anns
|
|
||||||
where
|
|
||||||
hasNum (DisableComment ts) = num == ts
|
|
||||||
hasNum _ = False
|
|
||||||
shouldIgnoreFor _ T_Include {} = not $ asCheckSourced asSpec
|
shouldIgnoreFor _ T_Include {} = not $ asCheckSourced asSpec
|
||||||
shouldIgnoreFor _ _ = False
|
shouldIgnoreFor code t = isAnnotationIgnoringCode code t
|
||||||
parents = parentMap params
|
parents = parentMap params
|
||||||
getCode = cCode . tcComment
|
getCode = cCode . tcComment
|
||||||
|
|
||||||
|
shouldIgnoreCode params code t =
|
||||||
|
any (isAnnotationIgnoringCode code) $
|
||||||
|
getPath (parentMap params) t
|
||||||
|
|
||||||
-- Is this a ${#anything}, to get string length or array count?
|
-- Is this a ${#anything}, to get string length or array count?
|
||||||
isCountingReference (T_DollarBraced id token) =
|
isCountingReference (T_DollarBraced id token) =
|
||||||
case concat $ oversimplify token of
|
case concat $ oversimplify token of
|
||||||
|
|
Loading…
Reference in New Issue