-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
inconsistent flagging of SC2178/SC2128 based on local
usage
#1309
Comments
This is probably because ShellCheck does not have proper control flow, similar to #1225 |
Similarly, there are cases when SC2128 gets misdetected because a variable comes from a caller's context. For example: #!/bin/bash
x() {
# Here we have args that came from y, i.e. args is an array.
# This is clearly SC2128 ("Expanding an array without an index ..."),
# but it is not detected.
echo x: "$args"
# Redeclare args as a string, shadowing the parent one.
local args="three four"
echo x: "$args"
}
y() {
# Here we have args that came from global context, i.e. args is an array.
# This is clearly SC2128 ("Expanding an array without an index ..."),
# but it is not detected.
echo y: "$args"
# Redeclare args.
local args=(one two)
echo y: "${args[@]}"
x
echo y: "${args[@]}"
}
args=(global args)
y |
Even with all local declarations on a separate line, I still get this issue when running checking multiple files at once. I only get the |
* Remove pip completion of pip2 * Apply Shellcheck 0.8.0 * (tue-env) use more local vars * Bump version to 1.3.9 * (tue-data) use more local * (tue-env-config) use more local * (tue-env-config) declare local vars on sep line * (tue-env-config) move main code to func to use local vars * (tue-data) declare local vars on sep line * (tue-env) declare local vars on sep line * (tue-functions) declare local vars on sep line * (tue-get) declare local vars on sep line * (tue-functions) use 'local -a' for arrays * Rename array to prevent shellcheck bug koalaman/shellcheck#1309
For bugs
Here's a snippet or screenshot that shows the problem:
if we start with this code:
we get:
but if we fix SC2155, all the other warnings disappear:
$ shellcheck myscript No issues detected!
if we remove the
local
decl, they come back:this is weird because the scope of var from
main
toget_vars
hasn't changed ... thelocal var
inmain
still cascades down intoget_var
.the SC2178/SC2128 should always be flagged even if the parent func declared it
local
for its own usage.The text was updated successfully, but these errors were encountered: