Pre-Commit Hooks

Pre-Commit Hooks

Non-Negotiables

  1. No bypassing hooks. If you need to bypass, the process is broken.
  2. Fast feedback wins. Hooks must be fast enough to run every commit.
  3. 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 -q subset)
  • TypeScript: eslint, prettier, tsc --noEmit subset
  • Java: format + Checkstyle (or equivalent)

References