mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-07 21:41:34 -07:00
Add bats support
This is motivated by the fact that the popularity of bats is increasing since the creation of bats-core/bats-core. The code is a cherry-pick of koalaman/shellcheck/bats branch. Fix koalaman/shellcheck#417.
This commit is contained in:
parent
c6c615217b
commit
f187382a0c
5 changed files with 37 additions and 1 deletions
|
@ -423,6 +423,7 @@ getVariableFlow params t =
|
|||
|
||||
assignFirst T_ForIn {} = True
|
||||
assignFirst T_SelectIn {} = True
|
||||
assignFirst (T_BatsTest {}) = True
|
||||
assignFirst _ = False
|
||||
|
||||
setRead t =
|
||||
|
@ -440,6 +441,7 @@ leadType params t =
|
|||
T_Backticked _ _ -> SubshellScope "`..` expansion"
|
||||
T_Backgrounded _ _ -> SubshellScope "backgrounding &"
|
||||
T_Subshell _ _ -> SubshellScope "(..) group"
|
||||
T_BatsTest {} -> SubshellScope "@bats test"
|
||||
T_CoProcBody _ _ -> SubshellScope "coproc"
|
||||
T_Redirecting {} ->
|
||||
if fromMaybe False causesSubshell
|
||||
|
@ -480,6 +482,12 @@ getModifiedVariables t =
|
|||
guard $ op `elem` ["=", "*=", "/=", "%=", "+=", "-=", "<<=", ">>=", "&=", "^=", "|="]
|
||||
return (t, t, name, DataString $ SourceFrom [rhs])
|
||||
|
||||
T_BatsTest {} -> [
|
||||
(t, t, "lines", DataArray SourceExternal),
|
||||
(t, t, "status", DataString SourceInteger),
|
||||
(t, t, "output", DataString SourceExternal)
|
||||
]
|
||||
|
||||
-- Count [[ -v foo ]] as an "assignment".
|
||||
-- This is to prevent [ -v foo ] being unassigned or unused.
|
||||
TC_Unary id _ "-v" token -> maybeToList $ do
|
||||
|
@ -699,6 +707,12 @@ getReferencedVariables parents t =
|
|||
then concatMap (getIfReference t) [lhs, rhs]
|
||||
else []
|
||||
|
||||
T_BatsTest {} -> [ -- pretend @test references vars to avoid warnings
|
||||
(t, t, "lines"),
|
||||
(t, t, "status"),
|
||||
(t, t, "output")
|
||||
]
|
||||
|
||||
t@(T_FdRedirect _ ('{':var) op) -> -- {foo}>&- references and closes foo
|
||||
[(t, t, takeWhile (/= '}') var) | isClosingFileOp op]
|
||||
x -> getReferencedVariableCommand x
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue