Running npm run pre-mit
takes a lot of time even if only one file has been changed.
package.json script:
"pre-mit": "lint-staged",
and lint-staged mands:
"lint-staged": {
"src/**/*.{ts,js,json}": [
"eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
],
"src/**/*.{js,ts,json}": [
"prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
]
},
It feels like eslint runs in the entire project How can I make it run only in the changed files?
Running npm run pre-mit
takes a lot of time even if only one file has been changed.
package.json script:
"pre-mit": "lint-staged",
and lint-staged mands:
"lint-staged": {
"src/**/*.{ts,js,json}": [
"eslint \"{src,apps,libs,test}/**/*.ts\" --fix"
],
"src/**/*.{js,ts,json}": [
"prettier --write \"src/**/*.ts\" \"test/**/*.ts\""
]
},
It feels like eslint runs in the entire project How can I make it run only in the changed files?
Share Improve this question asked Jun 9, 2022 at 12:39 rb27rb27 1713 silver badges10 bronze badges1 Answer
Reset to default 5You're asking eslint (and prettier) to run over the whole codebase by providing a glob. If you skip out the glob then each will run only on the file matched by lint-staged.
"lint-staged": {
"src/**/*.{ts,js,json}": [
"eslint --fix"
],
"src/**/*.{js,ts,json}": [
"prettier --write"
]
},
You can make this even better by bining the operations. Since they all run on the exact same set of files putting them in an array runs the operations sequentially and prevents conflicts between the two operations.
"lint-staged": {
"src/**/*.{ts,js,json}": [
"eslint --fix", "prettier --write"
],
"test/**/*.{js,ts,json}": [
"prettier --write"
]
},