feat: add lint rule for Bash nounset empty-argv forwarding#59
Open
olavostauros wants to merge 3 commits into
Open
feat: add lint rule for Bash nounset empty-argv forwarding#59olavostauros wants to merge 3 commits into
olavostauros wants to merge 3 commits into
Conversation
Adds bash-empty-argv-forwarding lint rule that flags "$@" and "${@}"
as command arguments in files with nounset enabled (set -u). This pattern
causes fatal unbound-variable errors on macOS Bash 3.2 when the argument
list is empty, while Linux Bash 5+ handles it silently.
The rule follows the established text-based ripgrep pattern from or-true,
caller-pwd-contract, etc. It correctly excludes safe contexts (for loops,
array assignments), already-safe alternate-value forms (${@+"$@"}),
and files without nounset.
Implements KnickKnackLabs#48 (KnickKnackLabs/codebase)
This was referenced Jun 26, 2026
Closed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
bash-empty-argv-forwardinglint rule that flags"$@"and"${@}"forwarded as command arguments in Bash files with nounset enabled (set -u). This pattern causes a fatalunbound variableerror on macOS Bash 3.2 when the argument list is empty, while Linux Bash 5+ handles it silently. ShellCheck does not catch this.Rule features:
set -u/set -eu/set -euo pipefailfor arg in "$@"loops andlocal arr=("$@")assignments are correctly excluded${@+"$@"}are not flagged# codebase:ignore bash-empty-argv-forwarding -- reasonand file-levelmise.tomlentriesor-true), sharedlib/shell-files.shhelpers, standard BATS test infrastructureValidation
mise run test— 255/255 tests pass, zero regressionsmise run lint:bash-empty-argv-forwarding .— self-hosting clean (only test fixtures flagged)git diff --check— no whitespace errorsCloses #48