Pre-Commit Hooks
Pre-Commit Hooks
Non-Negotiables
- No bypassing hooks. If you need to bypass, the process is broken.
- Fast feedback wins. Hooks must be fast enough to run every commit.
- Hooks enforce formatting and basic correctness. CI enforces the full suite.
Minimum Requirements
What must run locally
- Formatting (the repo’s formatter).
- Linting (the repo’s linter).
- Lightweight tests (smoke/unit subset) when feasible.
- Secret scanning (prevent credentials from landing in git history).
Rules
- Hooks must be deterministic.
- Hooks must use pinned versions.
- Hooks must run on staged files (avoid surprising edits).
Language Examples (typical)
- Python:
black,ruff, unit tests (pytest -qsubset) - TypeScript:
eslint,prettier,tsc --noEmitsubset - Java: format + Checkstyle (or equivalent)
References
- pre-commit (framework): https://pre-commit.com/
- Git hooks: https://git-scm.com/docs/githooks
- GitHub secret scanning: https://docs.github.com/en/code-security/secret-scanning