Add .claude/hooks for command auditing, dangerous command blocking, file protection, and auto-formatting; update documentation and configuration to integrate new hooks.
This commit is contained in:
34
.claude/hooks/post-edit-format.sh
Executable file
34
.claude/hooks/post-edit-format.sh
Executable file
@@ -0,0 +1,34 @@
|
||||
#!/bin/bash
|
||||
# Auto-format files after Edit/Write using Prettier
|
||||
# Event: PostToolUse | Matcher: Edit|Write
|
||||
# Silently skips if Prettier is not installed or file doesn't exist
|
||||
|
||||
INPUT=$(cat)
|
||||
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
|
||||
|
||||
if [ -z "$FILE_PATH" ] || [ ! -f "$FILE_PATH" ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
EXTENSIONS="ts tsx js jsx json css scss html md yaml yml"
|
||||
FILE_EXT="${FILE_PATH##*.}"
|
||||
|
||||
SHOULD_FORMAT=false
|
||||
for ext in $EXTENSIONS; do
|
||||
if [ "$FILE_EXT" = "$ext" ]; then
|
||||
SHOULD_FORMAT=true
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$SHOULD_FORMAT" = false ]; then
|
||||
exit 0
|
||||
fi
|
||||
|
||||
if command -v npx &>/dev/null && [ -f "node_modules/.bin/prettier" ]; then
|
||||
npx prettier --write "$FILE_PATH" 2>/dev/null
|
||||
elif command -v prettier &>/dev/null; then
|
||||
prettier --write "$FILE_PATH" 2>/dev/null
|
||||
fi
|
||||
|
||||
exit 0
|
||||
Reference in New Issue
Block a user