Fix issue #1724
(bash: missing support for 'builtin' keyword) Now shellcheck looks for the arguments to 'builtin' to determine read/written variables. A change in the parser makes sure that assignments are parsed correctly in commands that start with 'builtin'.
This commit is contained in:
parent
60f75e5b8a
commit
0e0de94045
|
@ -1,6 +1,7 @@
|
|||
## v0.7.1 - soon
|
||||
### Fixed
|
||||
- `-f diff` no longer claims that it found more issues when it didn't
|
||||
- SC2154 triggers for builtins called with `builtin`
|
||||
|
||||
### Added
|
||||
- SC2254: Suggest quoting expansions in case statements
|
||||
|
|
|
@ -2168,6 +2168,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 export var=4; echo $var"
|
||||
|
||||
checkUnassignedReferences = checkUnassignedReferences' False
|
||||
checkUnassignedReferences' includeGlobals params t = warnings
|
||||
|
|
|
@ -567,9 +567,11 @@ 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 id cmdPrefix (T_NormalWord _ (T_Literal _ x:_):rest)) =
|
||||
filter (\(_,_,s,_) -> not ("-" `isPrefixOf` s)) $
|
||||
case x of
|
||||
"builtin" ->
|
||||
getModifiedVariableCommand $ T_SimpleCommand id cmdPrefix rest
|
||||
"read" ->
|
||||
let params = map getLiteral rest
|
||||
readArrayVars = getReadArrayVariables rest
|
||||
|
|
|
@ -246,6 +246,10 @@ addParseNote n = do
|
|||
parseNotes = n : parseNotes state
|
||||
}
|
||||
|
||||
ignoreProblemsOf p = do
|
||||
systemState <- lift . lift $ Ms.get
|
||||
p <* (lift . lift . Ms.put $ systemState)
|
||||
|
||||
shouldIgnoreCode code = do
|
||||
context <- getCurrentContexts
|
||||
checkSourced <- Mr.asks checkSourced
|
||||
|
@ -2041,7 +2045,11 @@ readSimpleCommand = called "simple command" $ do
|
|||
|
||||
Just cmd -> do
|
||||
validateCommand cmd
|
||||
suffix <- option [] $ getParser readCmdSuffix cmd [
|
||||
-- We have to ignore possible parsing problems from the lookAhead parser
|
||||
firstArgument <- ignoreProblemsOf . optionMaybe . try . lookAhead $ readCmdWord
|
||||
suffix <- option [] $ getParser readCmdSuffix
|
||||
-- If `export` or other modifier commands are called with `builtin` we have to look at the first argument
|
||||
(if isCommand ["builtin"] cmd && isJust firstArgument then fromJust firstArgument else cmd) [
|
||||
(["declare", "export", "local", "readonly", "typeset"], readModifierSuffix),
|
||||
(["time"], readTimeSuffix),
|
||||
(["let"], readLetSuffix),
|
||||
|
|
Loading…
Reference in New Issue