array-without-index
What it does
Section titled “What it does”Reports $BASH_SOURCE, $FUNCNAME and the other bash arrays used without a subscript.
Why it matters
Section titled “Why it matters”$BASH_SOURCE is the same as ${BASH_SOURCE[0]}: the first element only. A reader may expect the whole array or the top of the stack, and the code is wrong when the element that was meant is another one.
To fix, write the subscript: ${BASH_SOURCE[0]}.
Example
Section titled “Example”...A=1 cmd "$B"A=1 cmd "$A_"echo "$FUNCNAME" "${FUNCNAME[0]}"Configuration
Section titled “Configuration”shell: lint: rules: array-without-index: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line array-without-index in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools. full: Sudsy reports what the upstream rule reports; partial: only part of it, as the last column says.
| Tool | Rule | Match | What differs |
|---|---|---|---|
| shellcheck | SC2128 |
partial | Only the bash arrays BASH_SOURCE, FUNCNAME and the like; user arrays need their declarations. |