Skip to content

Commit dc51307

Browse files
sjnimsclaude
andcommitted
fix: resolve shellcheck SC1087 errors in validate-hook-schema.sh
Replace unbraced variable syntax `$event[$i]` with proper brace expansion `${event}[$i]` in 11 locations. While bash interprets both correctly (since $event is a scalar, not an array), shellcheck flags the unbraced syntax as an error. This brings the script into compliance with shellcheck and aligns with the project's code quality standards per CONTRIBUTING.md. Fixes #167 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent 73b9a63 commit dc51307

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

plugins/plugin-dev/skills/hook-development/scripts/validate-hook-schema.sh

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,15 +69,15 @@ for event in $(jq -r 'keys[]' "$HOOKS_FILE"); do
6969
# Check matcher exists
7070
matcher=$(jq -r ".\"$event\"[$i].matcher // empty" "$HOOKS_FILE")
7171
if [ -z "$matcher" ]; then
72-
echo "$event[$i]: Missing 'matcher' field"
72+
echo "${event}[$i]: Missing 'matcher' field"
7373
((error_count++))
7474
continue
7575
fi
7676

7777
# Check hooks array exists
7878
hooks=$(jq -r ".\"$event\"[$i].hooks // empty" "$HOOKS_FILE")
7979
if [ -z "$hooks" ] || [ "$hooks" = "null" ]; then
80-
echo "$event[$i]: Missing 'hooks' array"
80+
echo "${event}[$i]: Missing 'hooks' array"
8181
((error_count++))
8282
continue
8383
fi
@@ -89,13 +89,13 @@ for event in $(jq -r 'keys[]' "$HOOKS_FILE"); do
8989
hook_type=$(jq -r ".\"$event\"[$i].hooks[$j].type // empty" "$HOOKS_FILE")
9090

9191
if [ -z "$hook_type" ]; then
92-
echo "$event[$i].hooks[$j]: Missing 'type' field"
92+
echo "${event}[$i].hooks[$j]: Missing 'type' field"
9393
((error_count++))
9494
continue
9595
fi
9696

9797
if [ "$hook_type" != "command" ] && [ "$hook_type" != "prompt" ]; then
98-
echo "$event[$i].hooks[$j]: Invalid type '$hook_type' (must be 'command' or 'prompt')"
98+
echo "${event}[$i].hooks[$j]: Invalid type '$hook_type' (must be 'command' or 'prompt')"
9999
((error_count++))
100100
continue
101101
fi
@@ -104,25 +104,25 @@ for event in $(jq -r 'keys[]' "$HOOKS_FILE"); do
104104
if [ "$hook_type" = "command" ]; then
105105
command=$(jq -r ".\"$event\"[$i].hooks[$j].command // empty" "$HOOKS_FILE")
106106
if [ -z "$command" ]; then
107-
echo "$event[$i].hooks[$j]: Command hooks must have 'command' field"
107+
echo "${event}[$i].hooks[$j]: Command hooks must have 'command' field"
108108
((error_count++))
109109
else
110110
# Check for hardcoded paths
111111
if [[ "$command" == /* ]] && [[ "$command" != *'${CLAUDE_PLUGIN_ROOT}'* ]]; then
112-
echo "⚠️ $event[$i].hooks[$j]: Hardcoded absolute path detected. Consider using \${CLAUDE_PLUGIN_ROOT}"
112+
echo "⚠️ ${event}[$i].hooks[$j]: Hardcoded absolute path detected. Consider using \${CLAUDE_PLUGIN_ROOT}"
113113
((warning_count++))
114114
fi
115115
fi
116116
elif [ "$hook_type" = "prompt" ]; then
117117
prompt=$(jq -r ".\"$event\"[$i].hooks[$j].prompt // empty" "$HOOKS_FILE")
118118
if [ -z "$prompt" ]; then
119-
echo "$event[$i].hooks[$j]: Prompt hooks must have 'prompt' field"
119+
echo "${event}[$i].hooks[$j]: Prompt hooks must have 'prompt' field"
120120
((error_count++))
121121
fi
122122

123123
# Check if prompt-based hooks are used on supported events
124124
if [ "$event" != "Stop" ] && [ "$event" != "SubagentStop" ] && [ "$event" != "UserPromptSubmit" ] && [ "$event" != "PreToolUse" ]; then
125-
echo "⚠️ $event[$i].hooks[$j]: Prompt hooks may not be fully supported on $event (best on Stop, SubagentStop, UserPromptSubmit, PreToolUse)"
125+
echo "⚠️ ${event}[$i].hooks[$j]: Prompt hooks may not be fully supported on $event (best on Stop, SubagentStop, UserPromptSubmit, PreToolUse)"
126126
((warning_count++))
127127
fi
128128
fi
@@ -131,13 +131,13 @@ for event in $(jq -r 'keys[]' "$HOOKS_FILE"); do
131131
timeout=$(jq -r ".\"$event\"[$i].hooks[$j].timeout // empty" "$HOOKS_FILE")
132132
if [ -n "$timeout" ] && [ "$timeout" != "null" ]; then
133133
if ! [[ "$timeout" =~ ^[0-9]+$ ]]; then
134-
echo "$event[$i].hooks[$j]: Timeout must be a number"
134+
echo "${event}[$i].hooks[$j]: Timeout must be a number"
135135
((error_count++))
136136
elif [ "$timeout" -gt 600 ]; then
137-
echo "⚠️ $event[$i].hooks[$j]: Timeout $timeout seconds is very high (max 600s)"
137+
echo "⚠️ ${event}[$i].hooks[$j]: Timeout $timeout seconds is very high (max 600s)"
138138
((warning_count++))
139139
elif [ "$timeout" -lt 5 ]; then
140-
echo "⚠️ $event[$i].hooks[$j]: Timeout $timeout seconds is very low"
140+
echo "⚠️ ${event}[$i].hooks[$j]: Timeout $timeout seconds is very low"
141141
((warning_count++))
142142
fi
143143
fi

0 commit comments

Comments
 (0)