ci: enforce lint locally via pre-commit hook
The repo had a .pre-commit-config.yaml entry for golangci-lint already, but pinned to v1.61.0 — which doesn't grok the v2 schema we just migrated to, so it would crash if anyone ever ran it. Hence nobody did. Replace the third-party hook blocks with local hooks that call whatever tool is on the developer's PATH (gofumpt + go vet + golangci-lint). That way the version of each tool tracks what the developer would invoke by hand — no drift between hook config and binary. Add 'make setup' as a one-liner per-clone bootstrap: * installs gofumpt + golangci-lint via go install if missing * installs the pre-commit hooks via 'pre-commit install' end-of-file-fixer auto-fixed two existing files (web/static/css/ styles.css and ask.md) — trailing newlines, harmless.
This commit is contained in:
+32
-9
@@ -11,15 +11,38 @@ repos:
|
||||
- id: mixed-line-ending
|
||||
args: ["--fix=lf"]
|
||||
|
||||
- repo: https://github.com/dnephin/pre-commit-golang
|
||||
rev: v0.5.1
|
||||
# Go-specific hooks. Local hooks (rather than third-party repos) so
|
||||
# the version of each tool tracks whatever is on the developer's
|
||||
# PATH, matching what they'd use to run the same checks by hand.
|
||||
# Required tools:
|
||||
# * go (toolchain matching go.mod)
|
||||
# * gofumpt — `go install mvdan.cc/gofumpt@latest`
|
||||
# * golangci-lint — `go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@v2.1.6`
|
||||
#
|
||||
# Install + activate the hooks once per clone:
|
||||
# pre-commit install
|
||||
- repo: local
|
||||
hooks:
|
||||
- id: go-fmt
|
||||
- id: go-imports
|
||||
- id: go-vet-mod
|
||||
- id: go-mod-tidy
|
||||
- id: gofumpt
|
||||
name: gofumpt
|
||||
description: Format Go files with gofumpt (stricter superset of gofmt)
|
||||
entry: gofumpt -l -w
|
||||
language: system
|
||||
types: [go]
|
||||
pass_filenames: true
|
||||
|
||||
- id: go-vet
|
||||
name: go vet
|
||||
description: Run go vet across all packages
|
||||
entry: go vet ./...
|
||||
language: system
|
||||
types: [go]
|
||||
pass_filenames: false
|
||||
|
||||
- repo: https://github.com/golangci/golangci-lint
|
||||
rev: v1.61.0
|
||||
hooks:
|
||||
- id: golangci-lint
|
||||
name: golangci-lint
|
||||
description: Run golangci-lint against the whole module (matches CI)
|
||||
entry: golangci-lint run ./...
|
||||
language: system
|
||||
types: [go]
|
||||
pass_filenames: false
|
||||
|
||||
Reference in New Issue
Block a user