auto-format-staged
v1.0.1
Published
Zero-config pre-commit formatter and linter. Installs in 30 seconds, uses your existing Prettier & ESLint setup. No config files needed.
Maintainers
Readme
auto-format-staged
Zero-config pre-commit formatter and linter. Automatically detects and uses your project's Prettier and ESLint configuration.
Features
- 🚀 30-second setup - One command and you're done
- 🎯 Zero configuration - Uses your existing
.prettierrcand.eslintrc - 🚫 Blocks bad commits - Linting errors prevent commits (warnings don't)
- ⚡ Lightning fast - Only processes staged files
- 🪶 Tiny - ~ 11.5KB with zero dependencies
- 🔄 Auto-formats - Formats code and re-stages files automatically
Installation
Quick Start (For You)
npm install --save-dev auto-format-staged
npx auto-format-stagedDone! Now try committing some messy code:
echo "const x=1;const y=2" > test.js
git add test.js
git commit -m "test"
# ✨ File automatically formatted before commit!Recommended Setup (For Teams)
The quick start is great, but it only installs the hook for you. Your teammates would have to remember to run npx auto-format-staged after cloning.
For a fully automated setup that works for everyone, add a postinstall script to your project's package.json:
{
"name": "my-cool-project",
"scripts": {
"postinstall": "npx auto-format-staged"
}
}Now, every time any developer runs npm install, it will automatically run your setup script and ensure the hook is installed.
Every commit will:
- Lint staged files (errors block commit, warnings don't)
- Format staged files with Prettier
- Re-stage formatted files
Requirements
Your project should have at least one of:
prettier(for formatting)eslint(for linting)
Both are optional - the tool works with whatever you have installed.
How It Works
When you commit:
- Gets list of staged files
- Detects your project's ESLint config (if installed)
- Runs linter - only errors block the commit
- Detects your project's Prettier config (if installed)
- Formats files and re-stages them
- Commit proceeds
What Gets Processed
Linting: .js, .jsx, .ts, .tsx, .mjs, .cjs
Formatting: .js, .jsx, .ts, .tsx, .json, .css, .scss, .md, .html, .yml, .yaml
Uninstall
rm .git/hooks/pre-commit
npm uninstall auto-format-staged🤝 Contributing
Issues and PRs welcome! This is a simple tool, let's keep it that way.
License
MIT © Ahmed Zrouqui
