Skip to content

Commit 1722785

Browse files
wesmclaude
andcommitted
build: switch pre-commit hooks to prek
Replace the hand-rolled .githooks/pre-commit script with prek, matching the setup used in roborev. The local hook runs `make lint` which now includes `--fix` for auto-formatting. A separate `lint-ci` target preserves the no-fix behavior for CI. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
1 parent 496f9a8 commit 1722785

File tree

4 files changed

+37
-23
lines changed

4 files changed

+37
-23
lines changed

.githooks/pre-commit

Lines changed: 0 additions & 10 deletions
This file was deleted.

Makefile

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ LDFLAGS := -X main.version=$(VERSION) \
1111
LDFLAGS_RELEASE := $(LDFLAGS) -s -w
1212
DESKTOP_DIST_DIR := dist/desktop
1313

14-
.PHONY: build build-release install frontend frontend-dev dev desktop-dev desktop-build desktop-macos-app desktop-macos-dmg desktop-windows-installer desktop-linux-appimage desktop-app test test-short test-postgres test-postgres-ci postgres-up postgres-down e2e vet lint tidy clean release release-darwin-arm64 release-darwin-amd64 release-linux-amd64 install-hooks ensure-embed-dir help
14+
.PHONY: build build-release install frontend frontend-dev dev desktop-dev desktop-build desktop-macos-app desktop-macos-dmg desktop-windows-installer desktop-linux-appimage desktop-app test test-short test-postgres test-postgres-ci postgres-up postgres-down e2e vet lint lint-ci tidy clean release release-darwin-arm64 release-darwin-amd64 release-linux-amd64 install-hooks ensure-embed-dir help
1515

1616
# Ensure go:embed has at least one file (no-op if frontend is built)
1717
ensure-embed-dir:
@@ -168,8 +168,16 @@ e2e:
168168
vet: ensure-embed-dir
169169
go vet -tags fts5 ./...
170170

171-
# Lint Go code with project defaults
171+
# Lint Go code and auto-fix where possible (local development)
172172
lint: ensure-embed-dir
173+
@if ! command -v golangci-lint >/dev/null 2>&1; then \
174+
echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1" >&2; \
175+
exit 1; \
176+
fi
177+
golangci-lint run --fix ./...
178+
179+
# Lint Go code without fixing (for CI)
180+
lint-ci: ensure-embed-dir
173181
@if ! command -v golangci-lint >/dev/null 2>&1; then \
174182
echo "golangci-lint not found. Install with: go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.10.1" >&2; \
175183
exit 1; \
@@ -211,16 +219,13 @@ release-linux-amd64: frontend
211219
-ldflags="$(LDFLAGS_RELEASE)" -trimpath \
212220
-o dist/agentsview-linux-amd64 ./cmd/agentsview
213221

214-
# Install pre-commit hook, resolving the hooks directory via git so
215-
# this works in both normal repos and linked worktrees
222+
# Install pre-commit hooks via prek
216223
install-hooks:
217-
@hooks_rel=$$(git rev-parse --git-path hooks) && \
218-
hooks_dir=$$(cd "$$(dirname "$$hooks_rel")" && echo "$$PWD/$$(basename "$$hooks_rel")") && \
219-
git config --local core.hooksPath "$$hooks_dir" && \
220-
mkdir -p "$$hooks_dir" && \
221-
cp .githooks/pre-commit "$$hooks_dir/pre-commit" && \
222-
chmod +x "$$hooks_dir/pre-commit" && \
223-
echo "Installed pre-commit hook to $$hooks_dir/pre-commit"
224+
@if ! command -v prek >/dev/null 2>&1; then \
225+
echo "prek not found. Install with: brew install prek" >&2; \
226+
exit 1; \
227+
fi
228+
prek install
224229

225230
# Show help
226231
help:
@@ -248,7 +253,8 @@ help:
248253
@echo " postgres-down - Stop test PostgreSQL container"
249254
@echo " e2e - Run Playwright E2E tests"
250255
@echo " vet - Run go vet"
251-
@echo " lint - Run golangci-lint"
256+
@echo " lint - Run golangci-lint (auto-fix)"
257+
@echo " lint-ci - Run golangci-lint (no fix, for CI)"
252258
@echo " tidy - Tidy go.mod"
253259
@echo ""
254260
@echo " release - Release build for current platform"

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,10 +271,16 @@ make dev # run Go server in dev mode
271271
make frontend-dev # run Vite dev server (use alongside make dev)
272272
make desktop-dev # run Tauri desktop app in dev mode
273273
make test # Go tests (CGO_ENABLED=1 -tags fts5)
274-
make lint # golangci-lint
274+
make lint # golangci-lint (auto-fix)
275275
make e2e # Playwright E2E tests
276+
make install-hooks # install pre-commit hooks via prek
276277
```
277278

279+
Pre-commit hooks are managed with [prek](https://github.com/j178/prek).
280+
Run `brew install prek && make install-hooks` after cloning. The hook
281+
runs `make lint` on every commit, auto-fixing formatting issues. If the
282+
hook rewrites files, re-stage and re-commit.
283+
278284
## Desktop Development
279285

280286
The desktop app is a Tauri wrapper under `desktop/`. It launches

prek.toml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
minimum_prek_version = "0.3.6"
2+
3+
[[repos]]
4+
repo = "local"
5+
6+
[[repos.hooks]]
7+
id = "golangci-lint"
8+
name = "golangci-lint"
9+
language = "system"
10+
entry = "make lint"
11+
pass_filenames = false
12+
always_run = true

0 commit comments

Comments
 (0)