Lint-Staged
Installation
Section titled “Installation”See the official documentation.
npm i -D lint-stagedyarn add -D lint-stagedpnpm add -D lint-stagedbun add -d lint-stagedSettings
Section titled “Settings”These are basic .lintstagedrc.json settings.
{ "$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:
"lint-staged": "lint-staged"When configured with husky’s pre-commit hook, it will automatically run before each commit:
pnpm run lint-staged