效果:代码commit时,会自动检测eslint,如果有不规范的地方,会报错,阻断提交
先安装eslint
-
husky
yarn add husky -D
yarn add lint-staged -D
npx husky add .husky/pre-commit "npm run lint" -
package.json
{
"scripts": {
"lint-staged": "lint-staged",
"prepare": "husky install"
},
"lint-staged": {
"src/**/*.{js,jsx,ts,tsx}": [
"eslint --fix --ignore-path .eslintignore --color",
"git add"
]
},
}
网友评论