Technologies:
Tolerim
a day ago
What is the method for executing eslint exclusively on recent modifications?
I need to highlight eslint errors in new files for an old project. Although the pre-commit hook is functioning, the terminal keeps displaying old errors from the entire project. How can I resolve this issue? I have already attempted fixing eslint config and utilizing pre-commit hook. Here's the relevant code for your reference:
"lint": "eslint ./src",
"lint-fix": "eslint ./src --fix --color",
"lint-staged": {
"*.{js,jsx}": "npm run lint"
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
Answers(1)
Tolerim
a day ago
Verified Answer
It seems like your pre-commit hook is running eslint on the whole project, which is giving you old errors.
To fix this, you can modify your eslint script to only check for errors in changed files by adding the --cached flag.
Here's an example of how you can modify your eslint script:
"lint": "eslint --cache ./src",
"lint-fix": "eslint --cache ./src --fix --color"
By adding the --cache flag to your eslint script, it will only check for errors in changed files. This should help you avoid getting old errors in your terminal.