Skip to content

Commit 873a6ce

Browse files
sjnimsclaude
andauthored
refactor: use ERE instead of BRE in grep patterns for clarity (#159)
## Description Replace BRE (Basic Regular Expression) patterns with ERE (Extended Regular Expression) in grep commands for improved readability. ## Type of Change - [x] Refactoring (code change that neither fixes a bug nor adds a feature) ## Component(s) Affected - [x] Skills (methodology and best practices) ## Motivation and Context BRE with escaped alternation (`grep -q "a\|b"`) is harder to read than ERE (`grep -Eq "a|b"`). The escaped pipes are: - Easy to forget or get wrong - Less widely understood - May behave differently across grep implementations Fixes #154 ## Solution Changed `grep -q` to `grep -Eq` for patterns with alternation, removing the backslash escapes. ## Changes | File | Instances | |------|-----------| | `validate-agent.sh` | 2 | | `hook-linter.sh` | 9 | **Total: 11 instances** ## Testing - [x] shellcheck passes on both modified scripts - [x] Verified no BRE alternation patterns remain --- 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent b724743 commit 873a6ce

2 files changed

Lines changed: 10 additions & 10 deletions

File tree

plugins/plugin-dev/skills/agent-development/scripts/validate-agent.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -197,13 +197,13 @@ else
197197
fi
198198

199199
# Check for second person
200-
if ! echo "$SYSTEM_PROMPT" | grep -q "You are\|You will\|Your"; then
200+
if ! echo "$SYSTEM_PROMPT" | grep -Eq "You are|You will|Your"; then
201201
echo "⚠️ System prompt should use second person (You are..., You will...)"
202202
((warning_count++))
203203
fi
204204

205205
# Check for structure
206-
if ! echo "$SYSTEM_PROMPT" | grep -qi "responsibilities\|process\|steps"; then
206+
if ! echo "$SYSTEM_PROMPT" | grep -Eqi "responsibilities|process|steps"; then
207207
echo "💡 Consider adding clear responsibilities or process steps"
208208
fi
209209

plugins/plugin-dev/skills/hook-development/scripts/hook-linter.sh

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -53,13 +53,13 @@ check_script() {
5353
fi
5454

5555
# Check 4: Reads from stdin
56-
if ! grep -q "cat\|read" "$script"; then
56+
if ! grep -Eq "cat|read" "$script"; then
5757
echo "⚠️ Doesn't appear to read input from stdin"
5858
((warnings++))
5959
fi
6060

6161
# Check 5: Uses jq for JSON parsing
62-
if grep -q "tool_input\|tool_name" "$script" && ! grep -q "jq" "$script"; then
62+
if grep -Eq "tool_input|tool_name" "$script" && ! grep -q "jq" "$script"; then
6363
echo "⚠️ Parses hook input but doesn't use jq"
6464
((warnings++))
6565
fi
@@ -79,19 +79,19 @@ check_script() {
7979
fi
8080

8181
# Check 8: Uses CLAUDE_PLUGIN_ROOT
82-
if ! grep -q "CLAUDE_PLUGIN_ROOT\|CLAUDE_PROJECT_DIR" "$script"; then
82+
if ! grep -Eq "CLAUDE_PLUGIN_ROOT|CLAUDE_PROJECT_DIR" "$script"; then
8383
echo "💡 Tip: Use \$CLAUDE_PLUGIN_ROOT for plugin-relative paths"
8484
fi
8585

8686
# Check 9: Exit codes
87-
if ! grep -q "exit 0\|exit 2" "$script"; then
87+
if ! grep -Eq "exit 0|exit 2" "$script"; then
8888
echo "⚠️ No explicit exit codes (should exit 0 or 2)"
8989
((warnings++))
9090
fi
9191

9292
# Check 10: JSON output for decision hooks
93-
if grep -q "PreToolUse\|Stop" "$script"; then
94-
if ! grep -q "permissionDecision\|decision" "$script"; then
93+
if grep -Eq "PreToolUse|Stop" "$script"; then
94+
if ! grep -Eq "permissionDecision|decision" "$script"; then
9595
echo "💡 Tip: PreToolUse/Stop hooks should output decision JSON"
9696
fi
9797
fi
@@ -104,15 +104,15 @@ check_script() {
104104
fi
105105

106106
# Check 12: Error messages to stderr
107-
if grep -q 'echo.*".*error\|Error\|denied\|Denied' "$script"; then
107+
if grep -Eq 'echo.*".*error|Error|denied|Denied' "$script"; then
108108
if ! grep -q '>&2' "$script"; then
109109
echo "⚠️ Error messages should be written to stderr (>&2)"
110110
((warnings++))
111111
fi
112112
fi
113113

114114
# Check 13: Input validation
115-
if ! grep -q "if.*empty\|if.*null\|if.*-z" "$script"; then
115+
if ! grep -Eq "if.*empty|if.*null|if.*-z" "$script"; then
116116
echo "💡 Tip: Consider validating input fields aren't empty"
117117
fi
118118

0 commit comments

Comments
 (0)