This repository contains and bundles pre-commit hooks that we use for development, linting and CI.
This repository derives code from, wraps, or directly leverages the following open source projects.
- iamthefij/docker-pre-commit - MIT
- golang.org/goimports - Go License
- hadolint/hadolint - GPLv3
- fzipp/gocyclo - BSD
- dnephin/pre-commit-golang - MIT
- princjef/gomarkdoc
This section tells you how to install.
First you must have pre-commit installed and configured.
The pre-commit hooks in this section require that the golang environment be installed to run successfully:
- go-test-unit
- go-build
- golangci-lint
- go-mod-tidy
- go-vet
- go-fmt
- gomarkdoc
The remaining hooks all run in containers, so require Docker installed to run successfully:
- gocyclo
- goimports
- gofmt
Use the following in your .pre-commit-config.yaml
to enable hooks. Note that
in this example, some of the hooks enabled would be redundant.
repos:
- repo: https://github.com/turo/pre-commit-hooks
rev: v3.5.0 # You may version pin this if desired
hooks:
- id: go-test-unit
- id: go-build
- id: go-mod-tidy
- id: go-vet
- id: go-fmt
- id: gomarkdoc
- id: gocyclo
- id: goimports
- id: gofmt
- id: golangci-lint
- id: docker-lint
- id: docker-compose-lint
This repository provides a single source for commonly used hooks. Usage is via the pre-commit git and CI hooks, rather than direct activation.
The following hooks are available:
Go
- golangci-lint (requires golang, golangci-lint) - Mega-meta-linter, contains all the other linters, may be slow to run the first time, but uses caching within the repository to speed up the container on subsequent runs. This should be your preferred Golang linter unless its just plain too slow.
- gocyclo (requires docker) - Cyclomatic complexity checker
- goimports (requres docker) - Superceded
go fmt
as the Go style formatter - gofmt (requires docker) - Original Go style formatter, a bit more relaxed
- go-test-unit (requires golang) - Runs all tests tagged with unit
- go-build (requires golang) - Build the repository to ensure it compiles
- go-mod-tidy (requires golang) - Clean up
go.mod
andgo.sum
- go-vet (requires golang) - Additional checks not performed by compilation
- go-fmt (requires golang) - Original style formatter, local version
- gomarkdoc (requires golang, gomarkdoc) - Generate documentation from packages
Docker
- docker-lint (requires docker) - Runs hadolint on Dockerfiles
- docker-compose-lint (requires docker) - Runs docker-compose config on compose files
A typical pre-commit-config.yaml
for a Golang project would look like this:
repos:
- repo: https://github.com/turo/pre-commit-hooks
rev: v3.5.0 # You may version pin this if desired
hooks:
- id: go-mod-tidy # Clean up go.mod
- id: go-build # Check compilation
- id: golangci-lint # Lint everything
- id: go-test-unit # Run unit tests
- id: gomarkdoc # Generate documenation
The version of the hook, e.g. golangci-lint
, that is actually used by this Action may be made available
via instructions in the packer-github-actions-general
GitHub repository. Thus, please refer to
that repository to upgrade any specific hook version.
Feel free to Pull Request this repository to add any commonly used hooks which you feel belong here.
https://pre-commit.com/#developing-hooks-interactively
pre-commit try-repo ../pre-commit-hooks go-cyclo --verbose --all-files
Right now we are manually publishing updates to hook images based on their
upstream changes. To facilitate this, the repo provides a script/build
script
to build either individual images or all of them.
script/build <hook_name>
- Build an individual imagescript/build all
- Build all images
Use docker push
to publish images if you have write access to the GitHub Packages.
- shakefu - Creator, maintainer
For changes, see the Releases documentation.
- https://stackoverflow.com/questions/61730802/validate-k8s-yaml-files-in-a-git-repo
- https://github.com/stefanprodan/kube-tools
- https://github.com/stackrox/kube-linter
- https://kubeval.instrumenta.dev/
- https://pre-commit.com/hooks.html
- https://github.com/rhysd/actionlint
- https://git.iamthefij.com/iamthefij/docker-pre-commit
- https://github.com/fzipp/gocyclo
- https://github.com/TekWizely/pre-commit-golang
- https://github.com/dnephin/pre-commit-golang
- https://github.com/talos-systems/conform
- https://github.com/leodido/go-conventionalcommits
- https://github.com/alessandrojcm/commitlint-pre-commit-hook
- https://github.com/securego/gosec