Skip to main content

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

  1. golangci-lint supports various editors

Current pre-commit hooks

HookDescription
go-versionAttempts to load go version and verify it.
check-jsonAttempts to load all json files to verify syntax. For more see here.
check-merge-conflictCheck for files that contain merge conflict strings. For more see here.
check-yamlAttempts to load all yaml files to verify syntax. For more see here.
detect-private-keyChecks for the existence of private keys. For more see here.
trailing-whitespaceTrims trailing whitespace. For more see here.
markdownlintLinting rules for markdown files. For more see here.
shell-lintLinter for shell files including spell check. For more see here.
prettierAttempts to run prettier hook against the code.
eslintAttempts to run linting rules against the code base.
swaggerAttempts to run swagger validator for api, internal, order and dps endpoints.
mdspellSpellchecks Markdown files. For more see here.
markdown-tocWrapper script to generate table of contents on Markdown files.
go-importsAttempts to run command goimports which updates your Go import lines, adding missing ones and removing unreferenced ones. For more see here.
go-lintAttempts to run a linter against the go source code.
go-vetAttempts to examines Go source code and reports suspicious constructs, such as Printf calls whose arguments do not align with the format string.
gosecInspects source code for security problems by scanning the Go AST. For more see here.
gen-docsAttempts to generate table of contents for the README.md file in docs/ folder.
gofmtPart of golangci-lint linter and attempts to format go code
varcheckPart of golangci-lint linter and used to find unused global variables and constants
typecheckPart of golangci-lint linter and works like the front-end of a Go compiler, parses and type-checks Go code
structcheckPart of golangci-lint linter and finds an unused struct fields
deadcodePart of golangci-lint linter and used to find unused code

Troubleshooting pre-commit issues

Troubleshoot Precommit Hook Failures