The shflags command-line flags library creates variables at runtime
with a few well-defined functions. This causes shellcheck to spit out
lots of warnings about unassigned variables, as well as miss warnings
about unused flag variables.
We can address this with two parts:
1. Pretend that the shflags global variables are predefined like other
shell variables so that shellcheck doesn't expect users to set them.
2. Treat DEFINE_string, DEFINE_int, etc. as new commands that create
variables, similar to the existing read, local, mapfile, etc.
Part 1 can theoretically be addresssed without this by following sourced
files, but that doesn't help if people are otherwise not following
external sources.
The new behavior is on by default, similar to automatic bats test
behavior.
Addresses #1597
References of the form $var and ${var} both map to the same structure in
the AST, which prevents any later analysis functions from distinguishing
them. In preparation for adding checks that need this info, add a Bool
to T_DollarBraced that tracks whether the braces were seen at parsing
time and update all references so that this change is a no-op.
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.
Fixkoalaman/shellcheck#417.
The precedence order that is used to determine the shell
is the following:
1. ShellCheck directive
2. Shebang
3. File extension
A new field `asFallbackShell` has been
added to the record type `AnalysisSpec`.
Pattern matching in "do" requires a MonadFail context, which we don't have in
pure code. Instead, we'll use "case-of" to bind the part of the state that
we're interested in.
It used to only treat all trailing variables in read as varaible
declarings, but an array variable can be declared in other positions:
read -a foo -r
foo is a declared variable, and multiple such variables can be declared.