I am trying to use a pre-commit hook to detect eslint errors before commit happens. I am using husky and lint-staged. But it runs the lint command for all the files in src and not on staged files only. Here is my package.json file.
"scripts": {
"test:ci": "cross-env CI=true react-scripts test --bail --passWithNoTests",
"lint": "eslint src/**/*.{js,jsx}",
"lint:fix": "eslint . --fix",
"precommit": "npm run lint && npm run test:ci"
}
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.js": [
"npm run precommit"
],
"*.jsx": [
"npm run precommit"
]
}
Is there any way so that it works ONLY on staged files and not on other files present in the directory?