ref:main

Add pre-commit hook for `cargo fmt` + `cargo clippy` #5

closed Opened by cole.christensen@gmail.com

Links

No links yet.

Problem

Nothing catches formatting or lint drift before commit. CI catches it, but that means wasted round-trips and a red build on a PR that could’ve been clean. There’s no hook in the repo today — `.git/hooks/pre-commit` is empty on a fresh clone.

Proposal

Add a version-controlled `.githooks/pre-commit` that, when any staged file matches `*.rs`:

  1. `cargo fmt –all – –check` — fails fast on unformatted code
  2. `cargo clippy –all-targets –all-features – -D warnings` — fails on any lint warning

Skip entirely if no `.rs` files are staged (so non-Rust commits — docs, CI config — stay snappy).

Installation

Add `scripts/install-hooks.sh` that runs `git config core.hooksPath .githooks`. Contributors run it once per clone. Document in README.

Why not skip-on-CI-only?

CI is the safety net; pre-commit is the ergonomic layer. Catching a missing `cargo fmt` locally before the PR push saves a green→red→green cycle.

Why not pre-commit framework / lefthook?

Zero extra dependencies. A 15-line shell script is smaller than pulling in Python or Go tooling.

Acceptance criteria

  • `.githooks/pre-commit` is executable, runs both checks, exits non-zero on failure.
  • Skipped cleanly when no `.rs` files are staged (e.g. a README-only commit passes instantly).
  • `scripts/install-hooks.sh` wires `core.hooksPath` to `.githooks`.
  • README documents the install step.
  • Deliberately commit an unformatted file → hook blocks. Format → hook passes.