My shellcheck version (shellcheck --version or "online"): 0.7.1
[x] The rule's wiki page does not already cover this
[ ] I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
(I can't try since my repro consists of two files)
Here's a snippet or screenshot that shows the problem:
helpers.bash:
#!/bin/bash
FOO=bar
function prepare() {
echo $FOO
}
$ shellcheck -x a.bats
In a.bats line 10:
FOO=whatever
^-^ SC2034: FOO appears unused. Verify use (or export if used externally).
For more information:
https://www.shellcheck.net/wiki/SC2034 -- FOO appears unused. Verify use (o...
Here's what I wanted or expected to see:
No errors, like in the following example using pure bash:
helpers.bash:
#!/bin/bash
FOO=bar
function prepare() {
echo $FOO
}
a.sh:
#!/bin/bash
set -e
. helpers.bash
function test_default() {
prepare | grep -w bar
}
function test_override() {
FOO=whatever
prepare | grep -w whatever
}
test_default
test_override
Test execution to see if it works:
$ bash ./a.sh
bar
whatever
$ echo $?
0
shellcheck run (shows no warnings):
$ shellcheck -x ./a.sh
$ echo $?
0
Additional information
In case I move function prepare() from helpers.bash to the main a.bats file, the warning goes away.
The very same repro using pure bash (see above) does not result in a warning.
This probably means that bats' load statement is not recognized in a way similar to bash' source.
For bugs
shellcheck --version
or "online"): 0.7.1Here's a snippet or screenshot that shows the problem:
helpers.bash:
a.bats:
Here's what shellcheck currently says:
Here's what I wanted or expected to see:
No errors, like in the following example using pure bash:
helpers.bash:
a.sh:
Test execution to see if it works:
shellcheck run (shows no warnings):
Additional information
In case I move
function prepare()
fromhelpers.bash
to the main a.bats file, the warning goes away.The very same repro using pure bash (see above) does not result in a warning.
This probably means that bats'
load
statement is not recognized in a way similar to bash'source
.