380931b3a8
Bumping CI to v2.5.0 surfaced two new gofumpt findings (in two test files that gofumpt v2.1.6 considered fine). Local re-format with the matching tool brings them in line. Pre-commit hook config: prepend $GOPATH/bin to PATH inside the hook entry so gofumpt + golangci-lint resolve when ~/go/bin isn't on the operator's interactive shell PATH (common — go install puts them there but PATH config varies). Without this, the hooks fail with 'Executable not found' even when the tools are installed. Pin the Makefile setup target to v2.5.0 so a fresh clone gets the same binary CI runs — keeps pre-commit and CI from drifting again.
49 lines
1.6 KiB
YAML
49 lines
1.6 KiB
YAML
repos:
|
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
|
rev: v4.6.0
|
|
hooks:
|
|
- id: trailing-whitespace
|
|
- id: end-of-file-fixer
|
|
- id: check-yaml
|
|
- id: check-added-large-files
|
|
args: ["--maxkb=512"]
|
|
- id: check-merge-conflict
|
|
- id: mixed-line-ending
|
|
args: ["--fix=lf"]
|
|
|
|
# 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: gofumpt
|
|
name: gofumpt
|
|
description: Format Go files with gofumpt (stricter superset of gofmt)
|
|
entry: bash -c 'PATH="$(go env GOPATH)/bin:$PATH" exec 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
|
|
|
|
- id: golangci-lint
|
|
name: golangci-lint
|
|
description: Run golangci-lint against the whole module (matches CI)
|
|
entry: bash -c 'PATH="$(go env GOPATH)/bin:$PATH" exec golangci-lint run ./...'
|
|
language: system
|
|
types: [go]
|
|
pass_filenames: false
|