mirror of
https://github.com/koalaman/shellcheck
synced 2025-08-22 06:13:54 -07:00
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:
parent
0f15fa49ba
commit
ae6a998db7
2 changed files with 6 additions and 1 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue