vue中eslintrc.js配置最详细介绍

2020-06-14 05:59:31易采站长站整理

* "error" 或者2 将规则打开为错误(触发时退出代码为1)
* 如:'no-restricted-syntax': 0, // 表示关闭该规则
* 【】如果某项规则,有额外的选项,可以通过数组进行传递,而数组的第一位必须是错误级别。如0,1,2
* 如 'semi': ['error', 'never'], never就是额外的配置项
*/
rules: {
/**
* 具体规则
* 【】具体的规则太多,就不做介绍了,有兴趣的同学可以上eslint官网查
* 【】注意 xxx/aaa 这些规则是 xxx 插件自定的规则,在eslint官网是查不到的。需要到相应的插件官网中查阅
* 【】如 import/extensions,这是「eslint-plugin-import」自定义的规则,需要到其官网查看 https://github.com/benmosher/eslint-plugin-import
*/
'import/extensions': ['error', 'always', {
js: 'never',
vue: 'never'
}],
'import/no-extraneous-dependencies': ['error', {
optionalDependencies: ['test/unit/index.js'] }],
'no-debugger': process.env.NODE_ENV === 'production' ? 'error' : 'off',
"no-restricted-syntax": 0, //
"guard-for-in": 0, //
"prefer-const": 0, //
"no-else-return": 0, //
"no-plusplus": 0, // 不允许使用++符号
"object-shorthand": ["error", "always", { "avoidQuotes": false }], // 去除禁止'videoData.isPause'(newValue) 的命名
"no-lonely-if": 0, // 不允许给函数参数重新赋值
"no-param-reassign": 0, // 不允许给函数参数重新赋值
"no-mixed-operators": 0, // 不允许混合使用运算符
"no-underscore-dangle": 0, // 不允许下划线作为变量名之一
"no-under": 0, // 不允许混合使用运算符
'generator-star-spacing': 'off',
'no-console': 'off', // 禁用no-console规则
'semi': ['error', 'never'], // 行尾不使用分号
'comma-dangle': ['error'],
'eqeqeq': 0, // 不需要强制使用全等
'max-len': 0,
'radix': 0,// parseInt不需要传第二个参数
'linebreak-style': 0, // 强制执行一致的换行样式,windows和mac不一样
'consistent-return': 0, // 箭头函数最后不需要最后强制return值
'no-unused-expressions': ["error", { "allowShortCircuit": true, "allowTernary": true }], // 允许您在表达式中使用三元运算符
'no-multi-spaces': ['error', { "ignoreEOLComments": true }],
}
}