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

SC2154/check-unassigned-uppercase does not report error for $1,... #3080

Open
4 tasks done
kkmuffme opened this issue Nov 11, 2024 · 4 comments
Open
4 tasks done

SC2154/check-unassigned-uppercase does not report error for $1,... #3080

kkmuffme opened this issue Nov 11, 2024 · 4 comments

Comments

@kkmuffme
Copy link

For bugs

For new checks and feature suggestions

Here's a snippet or screenshot that shows the problem:

#!/bin/bash
if [[ -n "$4" ]]
then
    echo "$5"
fi

Here's what shellcheck currently says:

No error

Here's what I wanted or expected to see:

5 is referenced but not assigned

The global variables $1, $2,... (not $0) should be checked like any other uppercase variable when check-unassigned-uppercase is used.
The numbers are easily fatfingered and this is an easy mistake to make when restructuring code too.

@wileyhy
Copy link

wileyhy commented Nov 15, 2024 via email

@kkmuffme
Copy link
Author

I think we are talking about quite different use cases. From what I come across, the most common case is bash foo.sh a b c d

@wileyhy
Copy link

wileyhy commented Nov 20, 2024 via email

@kkmuffme
Copy link
Author

Thanks, I know, but I have tons of legacy scripts.

There is actually a very simple fool's workaround I used: preprocess the script by replacing all (\$\{?)(\d) with \1sc_global_fake\2 since then those are just "regular" variables and shellcheck reports an error on them.

Therefore, I guess this would be easy enough to fix in shellcheck directly?

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

2 participants