Issue 1724 Support builtins in variable flow checks

https://github.com/koalaman/shellcheck/issues/1724

Add a pass through for builtin cmd to cmd for variable
assignment checks. Add test cases
This commit is contained in:
Gandalf- 2019-12-18 21:25:10 -08:00
commit ae6a998db7
2 changed files with 6 additions and 1 deletions

View file

@ -2129,6 +2129,7 @@ prop_checkUnused43= verifyTree checkUnusedAssignments "DEFINE_string foo '' ''"
prop_checkUnused44= verifyNotTree checkUnusedAssignments "DEFINE_string \"foo$ibar\" x y"
prop_checkUnused45= verifyTree checkUnusedAssignments "readonly foo=bar"
prop_checkUnused46= verifyTree checkUnusedAssignments "readonly foo=(bar)"
prop_checkUnused47= verifyNotTree checkUnusedAssignments "foo=1; builtin echo \"$foo\""
checkUnusedAssignments params t = execWriter (mapM_ warnFor unused)
where
flow = variableFlow params
@ -2189,6 +2190,7 @@ prop_checkUnassignedReferences35= verifyNotTree checkUnassignedReferences "echo
prop_checkUnassignedReferences36= verifyNotTree checkUnassignedReferences "read -a foo -r <<<\"foo bar\"; echo \"$foo\""
prop_checkUnassignedReferences37= verifyNotTree checkUnassignedReferences "var=howdy; printf -v 'array[0]' %s \"$var\"; printf %s \"${array[0]}\";"
prop_checkUnassignedReferences38= verifyTree (checkUnassignedReferences' True) "echo $VAR"
prop_checkUnassignedReferences39= verifyNotTree checkUnassignedReferences "builtin read -r foo; echo \"$foo\""
checkUnassignedReferences = checkUnassignedReferences' False
checkUnassignedReferences' includeGlobals params t = warnings

View file

@ -567,9 +567,12 @@ getReferencedVariableCommand _ = []
-- VariableName :: String, -- The variable name, i.e. foo
-- VariableValue :: DataType -- A description of the value being assigned, i.e. "Literal string with value foo"
-- )
getModifiedVariableCommand base@(T_SimpleCommand _ _ (T_NormalWord _ (T_Literal _ x:_):rest)) =
getModifiedVariableCommand base@(T_SimpleCommand i t (T_NormalWord _ (T_Literal _ x:_):rest)) =
filter (\(_,_,s,_) -> not ("-" `isPrefixOf` s)) $
case x of
"builtin" ->
getModifiedVariableCommand $ T_SimpleCommand i t rest
"read" ->
let params = map getLiteral rest
readArrayVars = getReadArrayVariables rest