I have configured eslint successfully to run for every commit (pre-commit hook) in reactjs project. It runs properly after sending git commit command to terminal.
here's my package.json
"scripts": {
......
"lint": "eslint src --ext .tsx .",
"lint:fix": "eslint src --ext .tsx --fix",
"precommit": "lint-staged",
"prepare": "husky install",
"format": "prettier --write \"src/**/*.tsx\"",
......
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.(ts|tsx)": [
"prettier --write .",
"eslint src --ext .tsx --fix .",
"git add ."
]
},
But I don't want eslint to check for rules when in development mode (by running npm run start
).
For example, I set no-console
rule to error
to prevent user to commit the code using console.log
in it, but when I try to use console.log
in development mode to show the log in console, it throw an error by lint check
How can I config it?
Thanks all
I myself found the solution from here Edit .env:
DISABLE_ESLINT_PLUGIN=true
Or in package.json:
{
"scripts": {
"start": "DISABLE_ESLINT_PLUGIN=true react-scripts start",
"build": "DISABLE_ESLINT_PLUGIN=true react-scripts build",
"test": "DISABLE_ESLINT_PLUGIN=true react-scripts test"
}
}