96 lines
3.9 KiB
JavaScript
96 lines
3.9 KiB
JavaScript
module.exports = {
|
||
root: true, // 根配置文件
|
||
parserOptions: {
|
||
// 语法解析器选项
|
||
parser: 'babel-eslint', // es6, 兼容箭头函数等
|
||
sourceType: 'module',
|
||
},
|
||
env: {
|
||
// 执行环境
|
||
browser: true,
|
||
node: true,
|
||
es6: true,
|
||
},
|
||
extends: ['plugin:vue/essential', 'eslint:recommended', 'prettier'], // 基础配置进行扩展
|
||
plugins: ['prettier'],
|
||
rules: {
|
||
// 校验规则
|
||
'vue/component-definition-name-casing': [2, 'PascalCase'], // vue组件name, PascalCase为大驼峰
|
||
'vue/require-prop-types': 2, // prop必须声明类型
|
||
'vue/v-bind-style': [1, 'shorthand'], // 动态绑定用缩写:
|
||
'vue/v-on-style': [1, 'shorthand'], // 事件绑定用缩写@
|
||
'vue/component-tags-order': [
|
||
2,
|
||
{
|
||
order: ['template', 'script', 'style'],
|
||
},
|
||
], // 模板顺序
|
||
|
||
// todo 根据env环境设置是否允许console和debugger
|
||
'no-console': process.env.NODE_ENV === 'production' ? 1 : 0, // 禁用 console
|
||
'no-debugger': process.env.NODE_ENV === 'production' ? 1 : 0, // 禁用 debugger
|
||
'require-await': 2, // 禁止使用不带 await 表达式的 async 函数
|
||
'constructor-super': 2, // 要求在构造函数中有 super() 的调用
|
||
'handle-callback-err': [2, '^(err|error)$'], // 要求回调函数中有容错处理
|
||
'new-cap': [
|
||
2,
|
||
{
|
||
newIsCap: true,
|
||
capIsNew: false,
|
||
},
|
||
], // 要求构造函数首字母大写
|
||
'no-caller': 2, // 禁用 arguments.caller 或 arguments.callee
|
||
'no-eval': 2, // 禁用 eval()
|
||
'no-extend-native': 2, // 禁止扩展原生类型
|
||
'no-extra-bind': 2, // 禁止不必要的 .bind() 调用
|
||
'no-extra-parens': [2, 'functions'], // 禁止不必要的括号
|
||
'no-floating-decimal': 2, // 禁止数字字面量中使用前导和末尾小数点
|
||
'no-implied-eval': 2, // 禁止使用类似 eval() 的方法
|
||
'no-iterator': 2, // 禁用 __iterator__ 属性
|
||
'no-label-var': 2, // 不允许标签与变量同名
|
||
'no-labels': [
|
||
2,
|
||
{
|
||
allowLoop: false,
|
||
allowSwitch: false,
|
||
},
|
||
], // 禁用标签语句
|
||
'no-lone-blocks': 2, // 禁用不必要的嵌套块
|
||
'no-multi-str': 2, // 禁止使用多行字符串
|
||
'no-array-constructor': 2, // 禁用 Array 构造函数
|
||
'no-new-object': 2, // 禁止使用new Object()
|
||
'no-new-require': 2, // 禁止调用 require 时使用 new 操作符
|
||
'no-new-wrappers': 2, // 禁止对 String,Number 和 Boolean 使用 new 操作符
|
||
'no-octal-escape': 2, // 禁止在字符串中使用八进制转义序列
|
||
'no-path-concat': 2, // 禁止对 __dirname 和 __filename 进行字符串连接
|
||
'no-proto': 2, // 禁用__proto__, 在 ECMAScript 3.1 中已经被弃用, 使用 Object.getPrototypeOf 和 Object.setPrototypeOf 代替
|
||
'no-return-assign': [2, 'except-parens'], // 禁止在 return 语句中使用赋值语句
|
||
'no-self-compare': 2, // 禁止自身比较
|
||
'no-sequences': 2, // 禁用逗号操作符
|
||
'no-throw-literal': 2, // 禁止抛出异常字面量
|
||
'no-unmodified-loop-condition': 2, // 禁用一成不变的循环条件
|
||
'no-unneeded-ternary': [
|
||
2,
|
||
{
|
||
defaultAssignment: false,
|
||
},
|
||
], // 禁止可以在有更简单的可替代的表达式时使用三元操作符
|
||
'no-useless-call': 2, // 禁止不必要的 .call() 和 .apply()
|
||
'no-useless-computed-key': 2, // 禁止在对象中使用不必要的计算属性
|
||
'no-useless-constructor': 2, // 禁用不必要的构造函数
|
||
'no-useless-escape': 0, // 禁用不必要的转义字符
|
||
'no-whitespace-before-property': 2, // 禁止属性前有空白
|
||
'operator-linebreak': [
|
||
2,
|
||
'after',
|
||
{
|
||
overrides: {
|
||
'?': 'before',
|
||
':': 'before',
|
||
},
|
||
},
|
||
], // 强制操作符使用一致的换行符风格,
|
||
'spaced-comment': [2, 'always'], // 强制在注释中 // 或 /* 使用一致的空格
|
||
},
|
||
}
|