feat: add lint rule for Bash nounset empty array expansions (#57)#62
Open
olavostauros wants to merge 3 commits into
Open
feat: add lint rule for Bash nounset empty array expansions (#57)#62olavostauros wants to merge 3 commits into
olavostauros wants to merge 3 commits into
Conversation
Adds bash-empty-array-expansions lint rule that flags ${array[@]}
and ${array[*]} under set -u (nounset), suggesting the Bash-3-safe
alternate-value form ${arr[@]+"${arr[@]}"}.
Shares nounset detection pattern with bash-empty-argv-forwarding (KnickKnackLabs#48):
- has_nounset() - detect set -u / set -eu / set -euo pipefail
- is_safe_context() - exclude for loops and local array assignments
- has_safe_form() - exclude already-safe alternate-value forms
Standard text-based ripgrep approach with 11 fixture scenarios and
15 BATS tests. ShellCheck-clean.
Implements KnickKnackLabs#57 (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-array-expansionslint rule that flags"${array[@]}"and"${array[*]}"under nounset (set -u), suggesting the Bash-3-safe alternate-value form${arr[@]+"${arr[@]}"}. macOS Bash 3.2 treats these as unbound variables when the array is empty; Linux Bash 5+ and Homebrew Bash handle them gracefully, creating a silent cross-platform gotcha. ShellCheck does not catch this.Also collapses decorative 3-line section comment blocks (
# ============ Section ============) to single-line headers (# Section) across 9.batstest files, per KKL convention (AGENTS.md rule #4).Files changed
.mise/tasks/lint/bash-empty-array-expansionstest/lint/bash-empty-array-expansions/bash-empty-array-expansions.batstest/lint/bash-empty-array-expansions/fixtures/.mise/tasks/lint/shellcheckcodebase:ignore(guarded usage).mise/tasks/lint/github-actionscodebase:ignore(guarded usage).mise/tasks/lint/mise-settingscodebase:ignore(guarded usage)test/lint/bats-test-task/fixtures/clean/mise.tomltest/lib/shell-files.batstest/lint/bats-test-helper/bats-test-helper.batstest/lint/bats-test-task/bats-test-task.batstest/lint/gum-table/gum-table.batstest/lint/mcr-scope/mcr-scope.batstest/lint/mise-settings/mise-settings.batstest/lint/or-true/or-true.batstest/lint/shellcheck/shellcheck.batstest/migrations/task-pattern/task-pattern.batstest/pre-commit/pre-commit.batstest/scan/scan.batsValidation
mise run test— 233/233 pass (15 new tests at indices 7–21, zero regressions)mise run lint:bash-empty-array-expansions .— self-hosting clean (only test fixtures flagged)mise run lint:shellcheck .mise/tasks/lint/bash-empty-array-expansions— ShellCheck-cleangit diff --check— no whitespace errorsSister issue
This is the array sibling of #48 (bash-empty-argv-forwarding, PR #59). Both share nounset detection logic and the safe-context exclusion pattern.
Closes #57