name: pre-commit description: > Run all pre-commit checks before committing. Run all quality checks including format check, clippy, tests, and verify no secrets or TODOs are staged.
Pre-Commit Skill
Run all quality checks before committing code changes.
Checks (in order)
1. Format Check
cargo fmt --check
Verify code is properly formatted. If this fails, run cargo fmt to fix.
2. Clippy Lint
cargo lint
Ensure no clippy warnings. Fix any issues before committing.
3. Run Tests
cargo test
Verify all tests pass. Do not commit if tests fail.
4. Check for TODOs/FIXMEs
git diff --cached | grep -E '^\+.*TODO|^\+.*FIXME' || true
Review any new TODO/FIXME comments. These should have associated issues.
5. Check for Secrets
# Check for potentially sensitive files
git diff --cached --name-only | grep -E '\.env|credentials|secret|key\.json' || true
# Check for API key patterns
git diff --cached | grep -E 'api[_-]?key|password|secret' || true
Never commit secrets. Use environment variables instead.
6. Check Staged Files
git status --short
Review what's being committed. Avoid committing:
.envfiles- Large binary files
- Generated files (build artifacts)
- Personal IDE settings
Quick Pre-Commit Script
Run all checks in sequence:
cargo fmt --check && \
cargo lint && \
cargo test && \
echo "All checks passed!"
Common Issues
| Check | Fix |
|---|---|
| Format failed | Run cargo fmt |
| Clippy warning | Fix the warning or #[allow(...)] with justification |
| Test failed | Fix the test or the code |
| Secret detected | Remove and use env var |
Example Output
Pre-Commit Checks:
[1/5] Format check... OK
[2/5] Clippy... OK (0 warnings)
[3/5] Tests... OK (261 passed)
[4/5] TODO/FIXME check... 0 new comments
[5/5] Secrets check... OK
All checks passed! Ready to commit.
If Checks Fail
- Do not use
--no-verifyto skip checks - Fix the issues
- Re-run checks
- Only commit when all checks pass
Commit Message Guidelines
After passing all checks, create a descriptive commit:
- Start with verb: Add, Fix, Update, Remove, Refactor
- Keep first line under 72 characters
- Add body for complex changes
- Reference issues if applicable