Open kkmuffme opened 5 days ago
set -u
is such a test, and it's specified by POSIX. Why risk getting it
wrong while reimplementing it when the availability of nounset is already
required?
Wiley
~ $ head -v test.sh ==> test.sh <==
set -u if [[ -n ${foo} ]] then echo "$foo" fi ~ $ ./test.sh
On Sun, Nov 10, 2024, 20:23 kkmuffme @.***> wrote:
For bugs
- Rule Id 2154:
- My shellcheck version: 0.10.0
- The rule's wiki page does not already cover this (e.g. https://shellcheck.net/wiki/SC2086)
- I tried on https://www.shellcheck.net/ and verified that this is still a problem on the latest commit
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:
!/bin/bashset -uif [[ -n "$foo" ]]then
echo "$foo"fi
Here's what shellcheck currently says:
No error Here's what I wanted or expected to see:
foo is referenced but not assigned with code SC2154
Since this is an error.
Correct/no error code e.g.
!/bin/bashset -uif [[ -n "${foo+x}" ]] && [[ -n "$foo" ]]then
echo "$foo"fi
While usually this is pointless, in some cases the "set -u" is outside of your control (= project requirements, set by a parent file that calls your script,...) and of course these issues always happen when you're on vacation :-) It would be helpful if there were a strict/pedantic mode for SC2154/check-unassigned-uppercase to check them as if "set -u" were set and report errors accordingly
— Reply to this email directly, view it on GitHub https://github.com/koalaman/shellcheck/issues/3081, or unsubscribe https://github.com/notifications/unsubscribe-auth/AUF2F25WKTVCDUO3PCLQQFD2AAWK3AVCNFSM6AAAAABRQ7NRESVHI2DSMVQWIX3LMV43ASLTON2WKOZSGY2DQMBZGUZDENI . You are receiving this because you are subscribed to this thread.Message ID: @.***>
For bugs
For new checks and feature suggestions
Here's a snippet or screenshot that shows the problem:
Here's what shellcheck currently says:
No error
Here's what I wanted or expected to see:
Since this is an error.
Correct/no error code e.g.
While usually this is pointless, in some cases the "set -u" is outside of your control (= project requirements, set by a parent file that calls your script,...) and of course these issues always happen when you're on vacation :-) It would be helpful if there were a strict/pedantic mode for SC2154/check-unassigned-uppercase to check them as if "set -u" were set and report errors accordingly