Context
In a project I have two files in:
src/ssl_certs/make_ssl_project_certs.sh
src/ssl_certs/make_ssl_root_certs.sh
The make_ssl_project_certs.sh
contains the global variables for those two scripts (along with some documentation). A large fraction of those global variables are also used in make_ssl_root_certs.sh
, and I would not want to create them twice.
Hence, I load both files from the main.sh
in the root of the repository with:
source src/ssl_certs/make_ssl_project_certs.sh
source src/ssl_certs/make_ssl_root_certs.sh
Error message
However, when I run pre-commit, which runs shellcheck, I retrieve the following error message:
C2153 (info): Possible misspelling: CA_PRIVATE_KEY_FILENAME may not be assigned. Did you mean ca_private_key_filename?
I include -x
in shellcheck via pre-commit with:
- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.9.0.2
hooks:
- id: shellcheck
name: check shell scripts with shellcheck
args: ["-x"]
files: ^.*\.(sh|bash|ksh)$
types: []
Approaches
I tried to resolve this issue by explicitly telling shellcheck to load the src/ssl_certs/make_ssl_project_certs.sh
file using in main:
# shellcheck source=src/ssl_certs/make_ssl_project_certs.sh
source src/ssl_certs/make_ssl_project_certs.sh
source src/ssl_certs/make_ssl_root_certs.sh
which did not yield a " SC1091 did not follow" error, however, it still yielded the SC2153 error the global (may) not be loaded, possible misspelling. So I also tried to tell shellcheck in the make_ssl_root_cert.sh
file that it loads those globals from the make_ssl_project_certs.sh
using:
# shellcheck source=src/ssl_certs/make_ssl_project_certs.sh
Which yielded the same SC2153 error, and I also tried, in that make_ssl_project_certs.sh
file:
# shellcheck source=make_ssl_project_certs.sh
Which yielded the same SC2153 error.
Question
How can I prevent specifying the global variables for those two files twice, whilst keeping them in the make_ssl_project_certs.sh
file and using them into the make_ssl_root_certs.sh
file without manually disabling all shellcheck warnings on those Globals not being declared/having a potential misspelling (SC2153)?
In essence, how do I tell shellcheck that those globals are loaded from the src/ssl_certs/make_ssl_project_certs.sh
file?
Note
I use the global variables with capitalisation, and within the functions, I use the same variable name uncapitalised as locals.
Another undesirable solution would be to include:
# shellcheck disable=SC2153
in the top of the make_ssl_root_certs.sh
file, because that could lead to ignoring actual mistakes.