Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Shellchecks follows sourced files even if the file was already sourced #2954

Open
svengit opened this issue Mar 28, 2024 · 0 comments
Open

Comments

@svengit
Copy link

svengit commented Mar 28, 2024

  • 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant