mirror of
https://github.com/luongnv89/claude-howto.git
synced 2026-04-26 09:56:01 +02:00
1a567be793
- Copy code/image/config files across all modules - Translate brand-voice and code-review templates - Translate CONTRIBUTING, CODE_OF_CONDUCT, SECURITY, STYLE_GUIDE - Copy CHANGELOG as-is (technical log) Ref: luongnv89/claude-howto#63
50 lines
1.2 KiB
Bash
50 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# Auto-format code after writing
|
|
# Hook: PostToolUse:Write
|
|
#
|
|
# Reads the target file path from stdin JSON and runs the appropriate formatter
|
|
# in-place on the file after Claude writes it.
|
|
#
|
|
# Compatible with: macOS, Linux, Windows (Git Bash)
|
|
|
|
# Read JSON input from stdin (Claude Code hook protocol)
|
|
INPUT=$(cat)
|
|
|
|
# Extract file_path using sed (compatible with all platforms)
|
|
FILE_PATH=$(echo "$INPUT" | sed -n 's/.*"file_path"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)
|
|
|
|
if [ -z "$FILE_PATH" ] || [ ! -f "$FILE_PATH" ]; then
|
|
exit 0
|
|
fi
|
|
|
|
# Detect file type and format accordingly
|
|
case "$FILE_PATH" in
|
|
*.js|*.jsx|*.ts|*.tsx)
|
|
if command -v prettier &> /dev/null; then
|
|
prettier --write "$FILE_PATH" 2>/dev/null
|
|
fi
|
|
;;
|
|
*.py)
|
|
if command -v black &> /dev/null; then
|
|
black "$FILE_PATH" 2>/dev/null
|
|
fi
|
|
;;
|
|
*.go)
|
|
if command -v gofmt &> /dev/null; then
|
|
gofmt -w "$FILE_PATH" 2>/dev/null
|
|
fi
|
|
;;
|
|
*.rs)
|
|
if command -v rustfmt &> /dev/null; then
|
|
rustfmt "$FILE_PATH" 2>/dev/null
|
|
fi
|
|
;;
|
|
*.java)
|
|
if command -v google-java-format &> /dev/null; then
|
|
google-java-format -i "$FILE_PATH" 2>/dev/null
|
|
fi
|
|
;;
|
|
esac
|
|
|
|
exit 0
|