Skip to content

Commit 9a61fbb

Browse files
JacobPEvansclaude
andcommitted
refactor(content-guards): replace fragile bash expansion with explicit branching
The previous fix (PR #39, commit 2202144) used ${config_flag[@]+"${config_flag[@]}"} to work around bash 3.2's unbound variable error with empty arrays. While functional, this expansion is: - Hard to read and understand - Easy to get wrong (even the commit message described it backwards) - Fragile across bash versions This change replaces the arcane parameter expansion with explicit conditional branching: - Check array length with ${#config_flag[@]} (works correctly under set -u) - Separate code paths for empty/non-empty arrays - Clear, maintainable, and works on all bash versions including macOS bash 3.2 Verified with /bin/bash (bash 3.2) under set -euo pipefail with both code paths. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent 2202144 commit 9a61fbb

1 file changed

Lines changed: 6 additions & 1 deletion

File tree

content-guards/scripts/validate-markdown.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,12 @@ EOF
104104
fi
105105
fi
106106

107-
if ! markdownlint_output=$(markdownlint-cli2 "${config_flag[@]+"${config_flag[@]}"}" "$file_path" 2>&1); then
107+
if [[ ${#config_flag[@]} -gt 0 ]]; then
108+
markdownlint_output=$(markdownlint-cli2 "${config_flag[@]}" "$file_path" 2>&1)
109+
else
110+
markdownlint_output=$(markdownlint-cli2 "$file_path" 2>&1)
111+
fi
112+
if [[ $? -ne 0 ]]; then
108113
errors+=("markdownlint-cli2 failed:")
109114
errors+=("$markdownlint_output")
110115
fi

0 commit comments

Comments
 (0)