Skip to content

Lint-Staged

See the official documentation.

Terminal window
npm i -D lint-staged

These are basic .lintstagedrc.json settings.

.lintstagedrc.json
{
"$schema": "https://json.schemastore.org/lintstagedrc.json",
"*.{js,jsx,ts,tsx}": ["eslint --fix", "prettier --write"],
"*.{css,scss}": ["stylelint --fix", "prettier --write"],
"*.{json,md,mdx,yml,yaml}": ["prettier --write"]
}

Lint-staged runs linters against staged git files. This is typically used with git hooks (via husky) to prevent committing code that doesn’t meet your linting standards.

Add this script to your package.json:

package.json
"lint-staged": "lint-staged"

When configured with husky’s pre-commit hook, it will automatically run before each commit:

.husky/pre-commit
pnpm run lint-staged