RFE: variant of `source=` directive that supports globbing
intelfx opened this issue · comments
For new checks and feature suggestions
- https://www.shellcheck.net/ (i.e. the latest commit) currently gives no useful warnings about this
- I searched through https://github.com/koalaman/shellcheck/issues and didn't find anything related
Here's a snippet or screenshot that shows the problem:
There is a pattern common to relatively large shell programs of loading multiple files with subroutines from a "library" directory, e.g.:
MAKEPKG_LIBRARY=${MAKEPKG_LIBRARY:-'@libmakepkgdir@'}
# Import libmakepkg
for lib in "$MAKEPKG_LIBRARY"/*.sh; do
source "$lib"
done
Here's what shellcheck currently says:
Shellcheck gives a single SC1090 at the source site, which is expected:
ShellCheck can't follow non-constant source. Use a directive to specify location.
However, this is not helpful because a source=
directive cannot be used to specify that multiple files should be imported at a single import site.
Here's what I wanted or expected to see:
I would like ShellCheck to have a directive (e.g. source-glob=
or perhaps source-list=
for especially complex cases) that would allow the user to specify that multiple files should be imported at this site:
for lib in "$MAKEPKG_LIBRARY"/*.sh; do
# shellcheck source-glob=libmakepkg/*.sh.in
source "$lib"
done
A question might arise on how to handle such directives inside loops; perhaps the answer (if ShellCheck does not do this already) is to only process this directive exactly once per source site.