ESLint的用途
- 审查代码是否符合编码规范和统一的代码风格
- 审查代码是否存在语法错误
官网
居然找到了一个中文网站:
http://eslint.cn/docs/user-guide/configuring#configuration-file-formats
开始使用
npm install eslint --save-de
https://eslint.org/docs/user-guide/getting-started
配置 ESlint
配置注释
可以使用块注释,来临时禁止规则出现警告
/* eslint-disable*/
console.log(1)
配置文件
ESLint 可以通过 .eslintrc.* file 或 package.json 中的 eslintConfig 字段来配置
.eslintrc.js:
module.exports = {
rules: {
'no-console': 'off',
},
};
package.json:
以下是vue-cli的默认配置
"eslintConfig": {
"root": true,
"env": {
"node": true
},
"extends": [
"plugin:vue/essential",
"eslint:recommended"
],
"rules": {},
"parserOptions": {
"parser": "babel-eslint"
}
},
vue-cli 配置 ESlint:
https://github.com/vuejs/vue-cli/tree/dev/packages/%40vue/cli-plugin-eslint
eslint 0, 1, 2 means
- “off” or 0 - turn the rule off
- “warn” or 1 - turn the rule on as a warning (doesn’t affect exit code)
- “error” or 2 - turn the rule on as an error (exit code will be 1)
http://eslint.org/docs/user-guide/getting-started#configuration
console 报错处理
https://eslint.org/docs/rules/no-console
用户总结:https://morning.work/page/maintainable-nodejs/getting-started-with-eslint.html