Shellchecks follows sourced files even if the file was already sourced
svengit opened this issue · comments
- My shellcheck version (
shellcheck --version
or "online"): Tried 0.8.0 and 0.10.0
Here's a snippet or screenshot that shows the problem:
I have several scripts with medium amounts of code in them. To allow for common functions to be scattered across those scripts each of them got an include guard like
#!/bin/bash
if [[ -v this_script_already_sourced ]]; then
return
else
readonly this_script_already_sourced=true
fi
# … rest of script
This works just fine for execution, but shellchecks seems to have problems with it. It does not detect that a script was already sourced and keeps sourcing them up to a certain point when called with -x
.
Test case: 4 scripts like the above which all source each other, e.g:
#!/bin/bash
if [[ -v A_SOURCED ]]; then
return
else
readonly A_SOURCED=true
fi
source b
source c
source d
Add sourcing /usr/bin/clevis-luks-common-functions
to one of them to have some actual code to parse.
Here's what shellcheck currently says:
time shellcheck -x a
real 0m4.254s
user 0m4.138s
sys 0m0.116s
Here's what I wanted or expected to see:
Faster parsing by ignoring scripts already "seen".
For real life examples I'm looking at times of 20+ seconds for shellcheck which really hurts when switching files via editor integration