File tree Expand file tree Collapse file tree 2 files changed +65
-0
lines changed
Expand file tree Collapse file tree 2 files changed +65
-0
lines changed Original file line number Diff line number Diff line change 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
Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments