安装依赖
yarn add eslint-config-airbnb eslint-config-prettier eslint-loader eslint-plugin-import eslint-plugin-jsx-a11y eslint-plugin-prettier eslint-plugin-react eslint-plugin-react-hooks husky lint-staged -D
eslint -init
写配置
这是我的配置(不定时按照使用的感受更新)
{
"env": {
"browser": true,
"es2021": true
},
"extends": [
"react-app",
"react-app/jest",
"plugin:prettier/recommended",
"plugin:react/recommended"
],
"rules": {
"prettier/prettier": [
"error",
{
"trailingComma": "none"
}
],
"react/no-unescaped-entities": 0,
"react/prop-types": 0,
"react/react-in-jsx-scope": "off",
"no-use-before-define": "off"
},
"ignorePatterns": [
"node_modules/",
"build/"
]
}
//package.json
{
...,
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
},
"lint-staged": {
"*.{js,jsx}": [
"eslint './src/**/*.{js,jsx}' --fix"
],
"package.json": [
"sort-package-json"
]
},
}
然后就可以提交前进行检查了