Run pre-commit hooks
Pre-commit is a powerful tool that automates validations, lint checks and adds to developer quality of life. The config file that determines the actions of pre-commit hooks can be found here.
Pre-commit can be run by running the following command in terminal:
pre-commit
or make pre_commit_tests
which is similar to how CircleCI runs it.
If the pre-commit
command is not found or errors out, please make sure you have the pre-requisites installed.
Testing
If you would like to run an individual hook, for example if you want to only run prettier: pre-commit run prettier -a
Editor Integration
golangci-lint
supports various editors
Current pre-commit hooks
Hook | Description |
---|---|
go-version | Attempts to load go version and verify it. |
check-json | Attempts to load all json files to verify syntax. For more see here. |
check-merge-conflict | Check for files that contain merge conflict strings. For more see here. |
check-yaml | Attempts to load all yaml files to verify syntax. For more see here. |
detect-private-key | Checks for the existence of private keys. For more see here. |
trailing-whitespace | Trims trailing whitespace. For more see here. |
markdownlint | Linting rules for markdown files. For more see here. |
shell-lint | Linter for shell files including spell check. For more see here. |
prettier | Attempts to run prettier hook against the code. |
eslint | Attempts to run linting rules against the code base. |
swagger | Attempts to run swagger validator for api, internal, order and dps endpoints. |
mdspell | Spellchecks Markdown files. For more see here. |
markdown-toc | Wrapper script to generate table of contents on Markdown files. |
go-imports | Attempts to run command goimports which updates your Go import lines, adding missing ones and removing unreferenced ones. For more see here. |
go-lint | Attempts to run a linter against the go source code. |
go-vet | Attempts to examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string. |
gosec | Inspects source code for security problems by scanning the Go AST. For more see here. |
gen-docs | Attempts to generate table of contents for the README.md file in docs/ folder. |
gofmt | Part of golangci-lint linter and attempts to format go code |
varcheck | Part of golangci-lint linter and used to find unused global variables and constants |
typecheck | Part of golangci-lint linter and works like the front-end of a Go compiler, parses and type-checks Go code |
structcheck | Part of golangci-lint linter and finds an unused struct fields |
deadcode | Part of golangci-lint linter and used to find unused code |