---
name: pre-commit
description: Run pre-commit checks (formatting, linting) before a commit. Use when the user says "run pre-commit", "format and lint", "check before committing", or when the commit skill needs to run pre-commit checks. Detects the project language and runs the appropriate tools.
version: 1.0.0
allowed-tools: [Bash, Read, Glob]
---

# Pre-Commit Checks

Run language-appropriate formatting and linting before a commit. Fix issues automatically where possible; report anything requiring manual intervention.

## Language Detection

Check the project root for the following files to determine which tools to run. A project may have multiple languages — run all that apply.

| File present | Tools to run |
|---|---|
| `Cargo.toml` | `cargo fmt --all`, `cargo clippy --all-targets --all-features -- -D warnings` |
| `package.json` | Check `package.json` scripts for `lint`/`format`; run `prettier --write .` if installed, then `eslint --fix .` if installed |
| `pyproject.toml` or `setup.py` | `ruff format .` if ruff present, else `black .`; then `ruff check --fix .` if ruff present |
| `go.mod` | `gofmt -w .` |
| `.clang-format` or `CMakeLists.txt` | `clang-format -i` on modified C/C++ files |

## Execution Order

1. **Detect languages** — check which config files exist.
2. **Run formatters** — apply all auto-formatters. Re-stage any files changed by formatting.
3. **Run linters** — run linters in check/fix mode. If a linter exits non-zero after auto-fix, report the remaining errors clearly.
4. **Re-stage formatted files** — run `git add -u` to include formatter changes in the commit.
5. **Report** — summarise what ran, what was fixed automatically, and any remaining issues.

## Rules

- Run `cargo fmt --all` before `cargo clippy`. Clippy output on unformatted code is noisy.
- For `cargo clippy`: treat warnings as errors (`-D warnings`). If clippy fails, do NOT proceed with the commit — report the errors and stop.
- Never skip checks silently. If a tool is not installed, say so.
- Never use `--no-verify` or equivalent bypass flags.
- If any check fails and cannot be auto-fixed, stop and report clearly. Do not commit broken code.

## Output

Report the result concisely:
- Which tools ran
- What was auto-fixed (list changed files)
- Any remaining errors that block the commit
