🛡️ Pre-commit Hooks Guide
Welcome to the guide for setting up and using pre-commit hooks in the Kepler Operator project! Pre-commit hooks help ensure code quality, consistency, and best practices before you push your changes. This guide will walk you through the setup and highlight all the hooks configured for this repository.
✨ Overview
Pre-commit hooks automatically check your code for common issues every time you make a commit. They help prevent mistakes, enforce standards, and save time during code reviews.
⚡ Installation & Setup
- Install pre-commit:
pip install pre-commit
- Install hooks in your local git repo:
pre-commit install
This command sets up the hooks to run automatically on git commit
.
- Run hooks on all files (optional, recommended for first-time setup):
pre-commit run --all-files
🔍 Configured Hooks
The following hooks are configured in .pre-commit-config.yaml
:
1. pre-commit-hooks
trailing-whitespace
: Removes trailing whitespace from lines.end-of-file-fixer
: Ensures files end with a newline. (Excludesdocs/api.md
)check-added-large-files
: Prevents committing large files.check-merge-conflict
: Detects merge conflict markers.
2. yamllint
yamllint
: Lints YAML files (excludesbundle
,config
,hack/crd
).
3. markdownlint
markdownlint
: Lints Markdown files (excludesdocs/api.md
).
4. codespell
codespell
: Checks for spelling mistakes. Ignores words in.codespellignore
and Go module files.
5. shellcheck
shellcheck
: Lints shell scripts with extended checks (-x
).
6. golangci-lint
golangci-lint
: Runs Go linters
7. commitlint
commitlint
: Ensures commit messages follow the conventional format. Runs on commit messages only.
8. reuse-lint-file
reuse-lint-file
: Checks Go files for REUSE compliance.
📝 Tips & Best Practices
- If a hook fails, follow the error message to fix the issue, then recommit.
- You can temporarily skip hooks with
git commit --no-verify
(not recommended). - To update hooks to their latest versions, run:
pre-commit autoupdate
- For more details, see the pre-commit documentation.
Happy committing! 🚀