npm i -D husky lint-staged
- In
package.json
"lint-staged": {
"src/**/*.{ts,tsx}": [
"tslint -c tslint.json --fix --format verbose",
"git add",
"react-scripts test --findRelatedTests"
]
},
"husky": {
"hooks": {
"pre-commit": "export CI=true && lint-staged",
"pre-push": "export CI=true && npm test"
}
},
Note,
We're using husky
and lint-staged
to lint and test code before commiting that's why you need at least Node's 8.12.0 version.
Note,
You shouldn't place space between ts
and tsx
in package.json
in lint-staged
section.
Wrong
"*.{ts, tsx}"
Right
"*.{ts,tsx}"