Skip to content

Commit 59060e4

Browse files
committed
feat: claude + lint/format on edit
1 parent d323748 commit 59060e4

File tree

2 files changed

+65
-0
lines changed

2 files changed

+65
-0
lines changed

.claude/hooks/format-lint.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# PostToolUse hook: format and lint Go files after Edit/Write
3+
INPUT=$(cat)
4+
FILE_PATH=$(echo "$INPUT" | jq -r '.tool_input.file_path // empty')
5+
6+
# Only process .go files
7+
if [[ "$FILE_PATH" != *.go ]]; then
8+
exit 0
9+
fi
10+
11+
# Check the file still exists (Write could have been to a new file that was then removed, etc.)
12+
if [[ ! -f "$FILE_PATH" ]]; then
13+
exit 0
14+
fi
15+
16+
# Format the file
17+
gofmt -w "$FILE_PATH" 2>&1
18+
19+
# Lint the file with auto-fix
20+
cd "$CLAUDE_PROJECT_DIR"
21+
go tool golangci-lint run --fix "$FILE_PATH" 2>&1
22+
23+
exit 0

.claude/settings.json

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
{
2+
"hooks": {
3+
"PostToolUse": [
4+
{
5+
"matcher": "Edit|Write",
6+
"hooks": [
7+
{
8+
"type": "command",
9+
"command": "\"$CLAUDE_PROJECT_DIR\"/.claude/hooks/format-lint.sh",
10+
"timeout": 30
11+
}
12+
]
13+
}
14+
]
15+
},
16+
"permissions": {
17+
"allow": [
18+
"Bash(just build)",
19+
"Bash(just test:*)",
20+
"Bash(just format:*)",
21+
"Bash(just lint:*)",
22+
"Bash(just lint-fix:*)",
23+
"Bash(just generate:*)",
24+
"Bash(just api:*)",
25+
"Bash(just sqlc:*)",
26+
"Bash(just docs:*)",
27+
"Bash(go build:*)",
28+
"Bash(go test:*)",
29+
"Bash(go fmt:*)",
30+
"Bash(go generate:*)",
31+
"Bash(go mod:*)",
32+
"Bash(go run:*)",
33+
"Bash(go tool golangci-lint:*)",
34+
"Bash(gofmt:*)"
35+
],
36+
"deny": [
37+
"Read(./.env)",
38+
"Read(./.env.*)",
39+
"Read(./.env.local)"
40+
]
41+
}
42+
}

0 commit comments

Comments
 (0)