Lint-Staged Addon
The Lint-Staged addon in Servest automates pre-commit checks to ensure only properly formatted and linted code is committed.
It integrates lint-staged and simple-git-hooks, adding an efficient Git hook setup that runs your linters and formatters only on changed files.
How It Works
When you run:
Loading code snippet…
Servest will:
-
Check the framework
Ensures your project uses a supported Node.js framework. If not, the operation is canceled. -
Detect whether your project uses JavaScript or TypeScript, and automatically adjusts file configurations if required.
-
Install Required Packages using your selected package manager (npm, pnpm, yarn, or bun).
Packages installed (with versions):
- lint-staged
- simple-git-hooks
-
Add postinstall Script
- Adds a postinstall script to your package.json if not already present:
Loading code snippet…
- Adds a postinstall script to your package.json if not already present:
-
Configure Git Hooks
- Adds a simple-git-hooks configuration that triggers lint-staged before every commit:
Loading code snippet…
- Adds a simple-git-hooks configuration that triggers lint-staged before every commit:
-
Add Lint-Staged Rules
- Adds a default configuration for Prettier to run automatically on all staged files:
Loading code snippet…
- Adds a default configuration for Prettier to run automatically on all staged files:
-
Confirm Setup
Once complete, Servest logs:- ✅ Added postinstall script
- ✅ Updated package.json with simple-git-hooks and lint-staged configs
- 🎉 Lint-Staged setup completed!
Example
After adding Lint-Staged to your backend project:
Loading code snippet…
Your package.json will include:
Loading code snippet…
This ensures that every time you commit, Prettier automatically formats your changed files — keeping your code clean and consistent across the team.
Notes
- Automatically detects your package manager (npm, pnpm, yarn, or bun).
- Safely re-runnable — won’t duplicate existing configs or scripts.
- Ensures consistent, formatted commits by running Prettier and linters before each commit.
- Integrates perfectly with ESLint and Prettier addons for a complete workflow.
Why It Matters
- Automates code formatting → No need to manually run Prettier before each commit.
- Prevents bad commits → Stops unformatted or invalid code before entering your repo.
- Ensures team consistency → Everyone commits code that follows the same formatting rules.
- Zero setup hassle → Adds and configures everything automatically inside your package.json.