Pre-Commit Hooks
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
Section titled “Quick Setup”# Install required toolsbrew install golangci-lint gosecpip3 install diff-cover
# Enable the hook (one-time)chmod +x .git/hooks/pre-commitOr use the installation script:
./scripts/install-hooks.shWhat Gets Checked
Section titled “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)
Normal Workflow
Section titled “Normal Workflow”Just commit as usual - the hook runs automatically:
git add .git commit -m "feat: add new feature"Skipping the Hook
Section titled “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
Section titled “Manual Verification”Run the same checks manually before pushing:
make verify # Run all checks (recommended)make lint-diff # Lint changed files onlymake test-coverage-diff # Check coverage on changesHow It Works
Section titled “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
Section titled “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
Section titled “Troubleshooting”Hook Not Running
Section titled “Hook Not Running”chmod +x .git/hooks/pre-commitMissing Tools
Section titled “Missing Tools”# golangci-lintbrew install golangci-lint
# gosec (security scanner)brew install gosec
# diff-coverpip3 install diff-coverCoverage Check Fails
Section titled “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
Section titled “Configuration”Changing Coverage Threshold
Section titled “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
Section titled “Disabling Specific Linters”Edit .golangci.yml to disable linters that don’t fit your workflow.