It seemed strange to me how everyone writing pre-commit hooks for Golang would choose to not use a great cross-platform language already in their disposal, Golang, and instead would write their hooks in something that is not cross-platform - BASH.
So I took some inspirations from other repos like https://github.com/Bahjat/pre-commit-golang and https://github.com/dnephin/pre-commit-golang and implemented the commands in Go.
This should work on Windows, Linux, Mac, and basically anything Golang does (though maybe not all the supported tools work on all platforms).
You can add these to your project's .pre-commit-config.yaml:
- repo: https://github.com/lietu/go-pre-commit
rev: v1.0.0
hooks:
- id: errcheck
- id: go-fmt-goimports
- id: go-test
- id: go-vet
- id: gofumpt
- id: golangci-lint
- id: golint
- id: staticcheck
- id: go-mod-tidyIf you want to use golangci-lint you should first follow
their installation guide. The other tools are automatically go install'd if they are not yet installed. If
you choose to use golangci-lint, you don't need errcheck, go-vet, and staticcheck separately, as they
are included by default.
Also you likely don't want to mix go-fmt-goimports with gofumpt as it is just a stricter variant of the
same tools.
This project has been made possible thanks to Cocreators and Lietu. You can help us continue our open source work by supporting us on Buy me a coffee.
