Don't warn about unused variables starting with _ (fixes #1498)

This commit is contained in:
Vidar Holen 2021-08-26 19:40:21 -07:00
parent c85ce2cb06
commit 81b7ee5598
2 changed files with 5 additions and 2 deletions

View File

@ -23,6 +23,7 @@
- SC2048: Warning about $\* now also applies to ${array[\*]}
- SC2181 now only triggers on single condition tests like `[ $? = 0 ]`.
- Quote warnings are now emitted for declaration utilities in sh
- Leading `_` can now be used to suppress warnings about unused variables
## v0.7.2 - 2021-04-19

View File

@ -2310,6 +2310,7 @@ prop_checkUnused44= verifyNotTree checkUnusedAssignments "DEFINE_string \"foo$ib
prop_checkUnused45= verifyTree checkUnusedAssignments "readonly foo=bar"
prop_checkUnused46= verifyTree checkUnusedAssignments "readonly foo=(bar)"
prop_checkUnused47= verifyNotTree checkUnusedAssignments "a=1; alias hello='echo $a'"
prop_checkUnused48= verifyNotTree checkUnusedAssignments "_a=1"
checkUnusedAssignments params t = execWriter (mapM_ warnFor unused)
where
flow = variableFlow params
@ -2326,8 +2327,9 @@ checkUnusedAssignments params t = execWriter (mapM_ warnFor unused)
unused = Map.assocs $ Map.difference assignments references
warnFor (name, token) =
warn (getId token) 2034 $
name ++ " appears unused. Verify use (or export if used externally)."
unless ("_" `isPrefixOf` name) $
warn (getId token) 2034 $
name ++ " appears unused. Verify use (or export if used externally)."
stripSuffix = takeWhile isVariableChar
defaultMap = Map.fromList $ zip internalVariables $ repeat ()