Pre-commit Hooks Guide
Overview
This project uses pre-commit to ensure code quality and consistency before commits are made. Pre-commit runs a series of checks and formatters on your code to catch issues early.
Installation
- Install pre-commit:
# Using pip
pip install pre-commit
- Install the git hooks in your local repository:
cd /path/to/kepler
pre-commit install
Available Hooks
Our pre-commit configuration includes the following hooks:
- trailing-whitespace: Trims trailing whitespace from lines
- end-of-file-fixer: Ensures files end with a newline
- check-added-large-files: Prevents large files from being committed
- check-merge-conflict: Prevents files with merge conflicts from being committed
- yamllint: Validates YAML files
- markdownlint: Validates Markdown files
- codespell: Checks for common misspellings
- golangci-lint: Runs Go linters
- commitlint: Validates commit messages against Conventional Commits format
- reuse-lint-file: Checks copyright and license information in files
- shell-fmt-go: Formats shell scripts using
shfmt
- shellcheck: Lints shell scripts
- helmlint: Lints Helm charts which requires
helm
command to be installed
Running Manually
You can run pre-commit manually on all files:
pre-commit run --all-files
Or on specific files:
pre-commit run --files path/to/file1 path/to/file2
Or run a specific hook:
pre-commit run <hook-id> --all-files
Commit Message Format
Our project follows the Conventional Commits specification:
<type>[optional scope]: <description>
[optional body]
[optional footer(s)]
Common types include:
- feat: A new feature
- fix: A bug fix
- docs: Documentation changes
- style: Changes that don't affect the code's meaning (formatting, etc.)
- refactor: Code changes that neither fix a bug nor add a feature
- test: Adding or correcting tests
- chore: Changes to the build process, tools, etc.
Updating Hooks
To update the hooks to their latest versions:
pre-commit autoupdate
Configuration Files
The project includes several configuration files:
.pre-commit-config.yaml
: Main pre-commit configuration.yamllint.yaml
: Configuration for YAML linting.markdownlint.yaml
: Configuration for Markdown linting.commitlintrc.yaml
: Configuration for commit message linting.codespellignore
: Words to ignore in spellchecking
Troubleshooting
For more help, run pre-commit --help
or refer to the official documentation.