javascript使用eslint执行代码检查
添加依赖包
npm install eslint --save-dev
npm install eslint-config-airbnb --save-dev
npm install eslint-plugin-import --save-dev
npm install eslint-plugin-jsx-a11y --save-dev
npm install eslint-plugin-react --save-dev
npm install babel-eslint --save-dev
项目根目录添加.eslintrc
文件,并修改内容
{
"extends": "airbnb",
"env": {
"browser": true,
"node": true,
"jest": true
},
"parser": "babel-eslint",
"ecmaFeatures": {
"forOf": true,
"jsx": true,
"es6": true
},
"rules": {
"no-undef": 0,
"no-console": 0,
"no-alert": 0,
"comma-dangle": 0,
"react/prop-types": 0,
"no-use-before-define": 0,
"radix": 0,
"no-param-reassign": 0,
"react/jsx-filename-extension": 0,
"no-mixed-operators": 0,
"import/prefer-default-export": 0,
"import/no-extraneous-dependencies": 0,
"no-plusplus": 0,
"react/prefer-stateless-function": 0,
"class-methods-use-this": 0,
"react/require-default-props": 0
},
"plugins": [
"react", "import"
],
"settings": {
"import/parser": "babel-eslint",
"import/resolve": {
"moduleDirectory": ["node_modules", "src"]
}
},
"globals": {
"__DEV__": true
}
}
如果使用vscode,可安装eslint插件