declare-and-assign-separately
What it does
Section titled “What it does”Reports export, local, declare, readonly or typeset with a command substitution as the value, as in local x=$(cmd).
Why it matters
Section titled “Why it matters”The exit status of the line is that of local, which succeeds, and not of cmd. A failing command is lost, even under set -e.
To fix, declare first and assign on the next line: local x; x=$(cmd).
Example
Section titled “Example”...[[ $x = $y ]] && [[ -n $(foo) ]]export out=$(make)local out="$(make)" x=1declare plain=1for f in $files; do :; doneConfiguration
Section titled “Configuration”shell: lint: rules: declare-and-assign-separately: warn # off (default), warn, errorEnabled by the presets: shell/shellcheck.
Suppress one line with sudsy-disable-next-line declare-and-assign-separately in a comment of the file’s language.
Upstream equivalents
Section titled “Upstream equivalents”The same check in other tools; Sudsy reports what each upstream rule reports.
| Tool | Rule | Match |
|---|---|---|
| shellcheck | SC2155 |
full |