This is a set of pre-commit
hooks for development across multiple languages.
Hooks:
todo-tags
: ensure all TODO comments reference a JIRA ticket (or any regex matcher)todo-branch-tags
: show all TODOs tagged with the ticket reference in the branch namebranch-name-check
: checks branch names adhere to the regex^(feature|bugfix|release|hotfix)\/.+
go-test
: runsgo test ./...
at the repo rootgo-dep-check
: ensure all your 3rd party Go packages are vendored (see dep)go-goimports
: ensure all the Go imports are included and orderedgo-golangci-lint
: a copy of the official lint config without forcing the--fix
argumentrust-check
: runscargo check
against all features & targetsrust-clippy
: runscargo clippy
lints in the repo rootrust-test
: runscargo test
at the repo root, includes all targets/features/examples/benchesrust-fmt
: runscargo fmt --all
rust-doc
: runscargo doc
against the workspace - great for linting intra-doc linksr-stylr
: runsstylr
to format R coder-lintr
: static analysis of R code withlintr
buf-lint
: runsbuf
lints against protobuf filesbuf-breaking
: protobuf breaking change detection usingbuf
repos:
- repo: https://github.com/domodwyer/pre-commit
rev: master
hooks:
- id: todo-tags # Requires python
stages: [commit, push, manual]
args: ["--tag=DEV"] # JIRA ticket tag (defaults to DEV)
# args: ["--regex='.*'"] # Or specify your own regex
- id: todo-branch-tags
stages: [post-checkout, manual] # Show tags when checking out
args: ["DEV"] # JIRA ticket tag
- id: branch-name-check
stages: [push]
- id: go-test
stages: [commit, push]
types: [go]
exclude: \.pb.go$ # Ignore generated protobuf files
args: ["-timeout=30s"] # Set a deadline (fast tests == happy developers)
- id: go-goimports
stages: [commit, push, manual]
types: [go]
exclude: \.pb.go$ # Ignore generated protobuf files
args: ["-local=itsallbroken.com"] # Separate local imports
- id: go-dep-check
stages: [push, manual]
types: [go]
- id: go-golangci-lint
args: [--new-from-rev=origin/master]
stages: [commit, push]
types: [go]
exclude: \.pb.go$
- id: rust-check
stages: [commit, push]
- id: rust-clippy
# args: [ # Optionally override default configured lints
# "-D rust_2018_idioms",
# "-D missing_docs",
#]
stages: [commit, push]
- id: rust-test
stages: [commit, push]
- id: rust-fmt
stages: [commit, push]
- id: rust-doc
stages: [push]
- id: r-stylr
stages: [commit, push]
- id: r-lintr
stages: [commit, push]
stages: [commit, push]
- id: buf-lint
stages: [commit, push]
- id: buf-breaking
# Checks against 'master' branch by defaut, change with:
# args: [".git#tag=v1.0.0"]
stages: [commit, push]
New TODOs introduced into the codebase should be tracked in JIRA so they're eventually done!
The todo-tags
hook searches changed files for TODO
comments (lines prefixed
by #
or //
) that do not reference a JIRA ticket. A valid TODO is in the
form: TODO(DEV-4242)
, where the DEV
tag is configurable, and 4242
is the
ticket number.
Instead for more flexibility, you can specify a custom regex to validate TODO tags with instead:
- id: todo-tags
stages: [commit, push, manual]
args: ["--regex='(dom|clive)'"]
The todo-branch-tags
is useful as a post-checkout
hook to print all TODOs
tagged with the ticket reference in the branch name. If you checkout a branch
called feature/DEV-4242-bananas
, all TODO(DEV-4242)
comments will be shown:
$ git checkout feature/DEV-4242-great-feature
Switched to branch 'feature/DEV-4242-great-feature'
Outstanding TODOs for the current branch.................................Failed
- hook id: find-branch-todos
- exit code: 1
./some/path/client.go
240: // TODO(DEV-4242): lock mutex before call
./some/path/client_test.go
2650: // TODO(DEV-4242): add test case for new feature
When adding new hooks you can run pre-commit try-repo .
for a quick syntax check.