PromptKit uses pre-commit hooks to maintain code quality. The hooks run automatically before each commit and only check changed code, making them fast and developer-friendly.
Quick Setup
# Install required tools
brew install golangci-lint gosec
pip3 install diff-cover
# Enable the hook (one-time)
chmod +x .git/hooks/pre-commit
Or use the installation script:
./scripts/install-hooks.sh
What Gets Checked
The pre-commit hook runs four checks:
- Linting - Only on changed Go files using
golangci-lint --new-from-rev=HEAD - Security - Security scanning with
gosecon changed code (if installed) - Tests - Only for packages with changes
- Coverage - Requires ≥80% test coverage on changed lines only (via
diff-cover)
Speed: Typically 15-35 seconds (vs. 2-4 minutes for full repo checks)
Usage
Normal Workflow
Just commit as usual - the hook runs automatically:
git add .
git commit -m "feat: add new feature"
Skipping the Hook
For emergencies or work-in-progress commits, include [skip-pre-commit] in your message:
git commit -m "wip: experimental changes [skip-pre-commit]"
Note: CI will still run full checks on your PR.
Manual Verification
Run the same checks manually before pushing:
make verify # Run all checks (recommended)
make lint-diff # Lint changed files only
make test-coverage-diff # Check coverage on changes
How It Works
The pre-commit system only checks code you’ve changed:
- Linting: Uses
--new-from-rev=HEADto only report issues in new/modified lines - Coverage: Uses
diff-coverto calculate coverage percentage for changed lines only
This means:
- ✅ You’re never blocked by legacy code issues
- ✅ All new code must pass quality checks
- ✅ Coverage improves gradually over time
CI Integration
GitHub Actions runs the same checks in the verify job:
- Downloads coverage from the test job
- Runs
diff-coveragainst the PR base branch - Posts results as a PR comment
- Fails the PR if coverage on changed lines is below 80%
Troubleshooting
Hook Not Running
chmod +x .git/hooks/pre-commit
Missing Tools
# golangci-lint
brew install golangci-lint
# gosec (security scanner)
brew install gosec
# diff-cover
pip3 install diff-cover
Coverage Check Fails
The hook shows which lines need test coverage. Options:
- Add tests for the changed lines (recommended)
- Use
[skip-pre-commit]if the code is truly not testable - Run
make test-coverage-diffto see a detailed report
Configuration
Changing Coverage Threshold
Edit the --fail-under value in:
Makefile(test-coverage-diff target).git/hooks/pre-commit.github/workflows/ci.yml(verify job)
Disabling Specific Linters
Edit .golangci.yml to disable linters that don’t fit your workflow.