refactor: batch Bash compat rules — empty array, empty-argv, variadic-args, exec-stderr-silence#74
Closed
olavostauros wants to merge 11 commits into
Closed
refactor: batch Bash compat rules — empty array, empty-argv, variadic-args, exec-stderr-silence#74olavostauros wants to merge 11 commits into
olavostauros wants to merge 11 commits into
Conversation
The codebase_target_for_rule() function treated the entire scope value as a single path, so a TOML string like or-true = ".mise/tasks lib" would produce a single target /repo/.mise/tasks lib (with space) instead of two separate targets /repo/.mise/tasks and /repo/lib. This meant multi-path scope overrides either errored (path doesn't exist) or silently scanned nothing — users thought they had multi-path coverage but got false passes. Changes: - lib/codebase-config.sh: Replace codebase_target_for_rule() with codebase_targets_for_rule() that splits the scope value on whitespace and emits one target line per token. - .mise/tasks/lint/_default: Iterate over the multi-line output so each target is linted independently. - test/lint/default.bats: Add test covering multi-path scope with space-separated path list. The fix uses shell word-splitting on the scope string (unquoted in a for loop), which naturally handles TOML string values with internal spaces. Each token is resolved as a relative path against the repo root, or passed through unchanged if absolute. Fixes KnickKnackLabs#22
Adds first-class lint groups/presets so repos can opt into convention bundles with a single @maintained-tool reference instead of enumerating every lint rule individually. Includes: - lib/lint-groups.sh — built-in group registry, expansion, and discoverability functions - lib/codebase-config.sh — source lint-groups.sh, expand @group references in codebase_configured_lint_rules(), support lint_exclude - .mise/tasks/lint/_default — show expanded group count in preamble; updated error hint to mention groups - .mise/tasks/lint/groups — new lint:groups discoverability task - test/lint/lint-groups/ — 17 BATS tests Closes KnickKnackLabs#69
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)
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)
Scans .mise/tasks/* for #USAGE directives with var=#true, then flags
dangerous consumption of the resulting usage_* vars:
- eval 'ARRAY=${usage_X}' → ERROR: injection vector
- read -ra ARRAY <<< "$usage_X" → WARN: loses quoting
The correct pattern uses xargs printf for bash or shlex.split() for
Python tasks, per mise-conventions.md.
…g no-tasks fixture
…r suppression Adds text-based detection for 'exec' with stderr redirection (2>/dev/null, 2>&-, 2>!) that persists for the current shell. - Detection via bash regex: \bexec\b[^#]*2> with dangerous target - Fixtures: clean, dirty, ignored-inline, ignored-file, broad-walk, no-toml, empty - 17 BATS tests covering detection, ignore mechanisms, discovery, edge cases - Self-hosting verified: task file does not self-report - Follows or-true pattern for output format, ignore conventions, and scope
This was referenced Jun 26, 2026
Open
Author
|
Closing this stacked batch in favor of individual re-evaluation. See ricon-family/olavo#9 for context. |
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
Stacked batch 3/4. See ricon-family/olavo#9.
Consolidates 4 Bash compatibility lint rules (supersedes #62, #59, #63, #67). These rules target macOS Bash 3.2 compatibility and common bash scripting pitfalls.
Rules included
bash-empty-array-expansionsbash-empty-argv-forwardingvariadic-argsexec-stderr-silenceexec ... 2>/dev/nullstderr suppressionCommits
b5040ecd29959dd809be9827405eb4f0f1ebdf41bb4e7b5376d1b69c2cb1d30Validation
mise run test— 312 tests passinggit diff --check— clean