Ultimate Pre-commit Code Formatter Inspector
Enterprise-ready hook that automates auto-format code before each commit. Built for Claude Code with best practices and real-world patterns.
Ultimate Pre-commit Code Formatter Inspector
Comprehensive multi-language code formatting inspector that validates formatting compliance across your entire codebase before every commit.
When to Use This Hook
Attach this hook when you need to:
- Enforce consistent code formatting across JavaScript, Python, Go, Rust, and other languages before commits
- Run multiple formatters (Prettier, Black, gofmt, rustfmt) in a single pre-commit pass
- Generate detailed formatting compliance reports with diff previews of required changes
Consider alternatives when:
- Your team uses a single language and a simple per-file formatting hook suffices
- You prefer post-commit formatting with auto-fix rather than pre-commit blocking
Quick Start
Configuration
name: ultimate-pre-commit-code-formatter-inspector type: hook trigger: PreToolUse category: code-review
Example Trigger
# Hook triggers before a git commit command git commit -m "feat: add user profile page" # Inspector runs formatters on all staged files
Example Output
Pre-commit Formatter Inspector
Staged files: 12
JavaScript/TypeScript (7 files):
Prettier: 5 pass, 2 need formatting
Python (3 files):
Black: 3 pass
Go (2 files):
gofmt: 2 pass
Summary: 2 files need formatting
src/components/UserProfile.tsx (Prettier)
src/hooks/useAuth.ts (Prettier)
Run: npx prettier --write src/components/UserProfile.tsx src/hooks/useAuth.ts
Core Concepts
Language Coverage Overview
| Aspect | Details |
|---|---|
| JavaScript/TypeScript | Prettier with project config (.prettierrc) |
| Python | Black with pyproject.toml settings |
| Go | gofmt (built into Go toolchain) |
| Rust | rustfmt with rustfmt.toml configuration |
| CSS/SCSS | Prettier with CSS parser |
| YAML/JSON | Prettier with appropriate parser selection |
Inspection Workflow
Commit Initiated
|
Get Staged Files
|
Group by Language
|
āāāāāā¼āāāāā¬āāāāā
| | | |
JS Py Go Rust
| | | |
Pret Blk gfmt rfmt
| | | |
āāāāāā¼āāāāā“āāāāā
|
Aggregate Results
|
āāāāāā“āāāāā
| |
All Pass Failures
| |
Allow Block +
Commit Show Fixes
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
formatters | object | auto-detected | Map of file extensions to formatter commands |
auto_fix | boolean | false | Automatically fix formatting instead of blocking |
check_only_staged | boolean | true | Only check files in the git staging area |
parallel | boolean | true | Run formatters for different languages in parallel |
show_diff | boolean | false | Show the exact formatting diff for each violation |
Best Practices
-
Auto-Detect Available Formatters - Check which formatters are installed and only run those. A missing formatter should generate a warning, not block the entire commit process.
-
Provide One-Command Fix - When the inspector finds formatting issues, output the exact command to fix all violations. Developers should be able to copy-paste and re-commit in seconds.
-
Check Only Staged Files - Running formatters on the entire codebase is slow and surfaces pre-existing issues. Focus on staged files to validate only what is being committed.
-
Support Auto-Fix Mode - For teams that prefer automatic formatting, enable
auto_fixmode to format files and re-stage them rather than blocking. This trades strictness for convenience. -
Cache Formatter Results - If a file has not changed since the last successful format check, skip it. Caching reduces inspection time for large commits with few changes.
Common Issues
-
Formatter Version Mismatch - Different developers with different formatter versions produce conflicting formats. Pin formatter versions in your project's package manager and document required versions.
-
Partial Staging Conflicts - When only part of a file is staged, formatting the full file can change unstaged lines. Use
git stash --keep-indexbefore formatting to isolate staged content. -
Formatter Timeout on Large Files - Some formatters are slow on files with thousands of lines. Set per-file timeouts and skip formatting for files that exceed them with a logged warning.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.