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
SC2115 fires when it is statically verifyable that the variable cannot be empty #2968
Comments
Personally I think it is always advisable to use "${var:?}". Put this case:
In this example there is a missing letter in the variable declaration, and this cause the second commands to wipe all your files. |
There's definitely a case to be made for safe habits. SC2086 has a corresponding optional/"strict" check, SC2248. Potentially, an optional version of this check could be useful, as well? I do think it would be nice to take advantage of the extra information by default. In the end, I certainly don't feel that the current behavior is bad, simply that it could perhaps be refined. This issue is really just the result of having been surprised by SC2115's behavior compared to SC2086. 🙂 As for the typo, that would still trigger SC2034 for the unused variable and SC2153 for the undefined variable, both of which I feel are more relevant to having made a typo than not knowing whether the misspelled variable is empty. |
For bugs
I had assumed this rule would work similarly to SC2086, in that it wouldn't trigger if the variable's declaration were available and could not lead to the described problem occurring. In the example below,
STEAMROOT
is declared within the script being checked and cannot be empty even ifHOME
is.Here's a snippet that shows the problem:
Here's what shellcheck currently says:
Here's what I expected to see:
The text was updated successfully, but these errors were encountered: