Skip to content

Commit 00aa4b2

Browse files
la14-1spawn-qa-bot
andauthored
fix: always reject set -u in shell script validation hook (#2427)
The validate-file.ts hook previously only blocked `set -u` when `set -eo pipefail` was absent from the file. This allowed scripts with both `set -eo pipefail` and `set -u` to pass validation, contradicting the shell rules that unconditionally ban nounset. Fix the regex to always reject `set -u` variants on actual set invocation lines (not comments or strings), and update the error message to recommend `${VAR:-}` instead. Co-authored-by: spawn-qa-bot <qa@openrouter.ai>
1 parent 73ab90f commit 00aa4b2

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

.claude/scripts/validate-file.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,11 @@ if (file.endsWith(".sh")) {
6666
fail(`echo -e detected in ${file} — use printf instead (macOS bash 3.x compat)`);
6767
}
6868

69-
// Check for set -u without set -eo pipefail
70-
if (/set\s+-.*u/.test(content) && !/set\s+-eo\s+pipefail/.test(content)) {
71-
fail(`set -u (nounset) detected in ${file} — use set -eo pipefail instead`);
69+
// Check for set -u (nounset) — always banned, even alongside set -eo pipefail.
70+
// Only match lines that actually invoke set (not comments or string literals).
71+
const setUPattern = /^\s*set\s+-[a-z]*u/m;
72+
if (setUPattern.test(content)) {
73+
fail(`set -u (nounset) detected in ${file} — use \${VAR:-} for optional vars instead`);
7274
}
7375
}
7476

0 commit comments

Comments
 (0)