Skip to content

feat: add lint rule for Bash nounset empty-argv forwarding#59

Open
olavostauros wants to merge 3 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/bash-empty-argv-forwarding
Open

feat: add lint rule for Bash nounset empty-argv forwarding#59
olavostauros wants to merge 3 commits into
KnickKnackLabs:mainfrom
olavostauros:feat/bash-empty-argv-forwarding

Conversation

@olavostauros

Copy link
Copy Markdown

Summary

Adds bash-empty-argv-forwarding lint rule that flags "$@" and "${@}" forwarded as command arguments in Bash files with nounset enabled (set -u). This pattern causes a fatal unbound variable error 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:

  • Nounset-gated: only flags files with set -u / set -eu / set -euo pipefail
  • Safe-context exclusions: for arg in "$@" loops and local arr=("$@") assignments are correctly excluded
  • Already-safe form detection: lines already using ${@+"$@"} are not flagged
  • Respects ignore mechanisms: inline # codebase:ignore bash-empty-argv-forwarding -- reason and file-level mise.toml entries
  • Follows established patterns: text-based ripgrep scan (same as or-true), shared lib/shell-files.sh helpers, standard BATS test infrastructure

Validation

  • mise run test — 255/255 tests pass, zero regressions
  • mise run lint:bash-empty-argv-forwarding . — self-hosting clean (only test fixtures flagged)
  • git diff --check — no whitespace errors

Closes #48

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)
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

Successfully merging this pull request may close these issues.

Lint Bash nounset empty-argv forwarding

1 participant