module.exports = {
root: true,
parserOptions: { //此项是用来指定javaScript语言类型和风格,sourceType用来指定js导入的方式,默认是script,此处设置为module,指某块导入方式
parser: 'babel-eslint',
sourceType: 'module'
},
env: { //此项指定环境的全局变量,
browser: true,
node: true,
es6: true,
},
extends: ['plugin:vue/recommended', 'eslint:recommended'],
// add your custom rules here
//it is base on https://github.com/vuejs/eslint-config-vue
rules: {
"vue/max-attributes-per-line": [2, {
"singleline": 10,
"multiline": {
"max": 1,
"allowFirstLine": false
}
}],
"vue/name-property-casing": ["error", "PascalCase"],
'accessor-pairs': 2, // 定义对象的set存取器属性时,强制定义get
'arrow-spacing': [2, { // 规则在箭头函数的箭头(=>)之前/之后标准化间距样式。
'before': true,
'after': true
}],
'block-spacing': [2, 'always'], //规则在打开的块令牌内和同一行上的下一个令牌内强制执行一致的间距。
'brace-style': [2, '1tbs', { // 规则为块执行一致的括号样式。
'allowSingleLine': true
}],
'camelcase': [0, { // 变量命名规范
'properties': 'always'
}],
'comma-dangle': [2, 'never'], // 强制在对象和数组文字中一致地使用尾随逗号。
'comma-spacing': [2, { // 规则在变量声明,数组文字,对象文字,函数参数和序列中的逗号前后加上一致的间距。
'before': false,
'after': true
}],
'constructor-super': 2, // 该规则检查是否存在有效的super()调用 [构造函数]。
'curly': [2, 'multi-line'], // 通过确保将块语句包装在花括号中来防止错误并提高代码清晰度。当它遇到忽略大括号的块时它会发出警告。 [if else]
'eol-last': 2, // 文件末尾强制换行
'eqeqeq': [0, 'allow-null'], // 随便想用啥 用啥
'generator-star-spacing': [2, { //生成器函数*的前后空格。
'before': true,
'after': true
}],
'handle-callback-err': [2, '^(err|error)$'], //nodejs 处理错误
'indent': [2, 2, { // 文本缩进
'SwitchCase': 1
}],
'jsx-quotes': [2, 'prefer-single'], // 此规则强制在 JSX 属性中一致使用单引号。
'key-spacing': [2, { // 强制在对象字面量属性中的键和值之间保持一致的间距。在长行的情况下,允许在允许空格的地方添加新行
'beforeColon': false,
'afterColon': true
}],
'keyword-spacing': [2, { // 围绕关键字和关键字标记的一致空格
'before': true,
'after': true
}],
'new-cap': [2, { // 要求构造函数名以大写字母开头。某些内置标识符可免除此规则。
'newIsCap': true,
'capIsNew': false
}],
'new-parens': 2, // 此规则在使用new关键字调用不带参数的构造函数时需要括号,以便提高代码清晰度
'no-array-constructor': 2, // 此规则不允许使用Array构造函数
'no-caller': 2,
'no-console': 'off',
'no-class-assign': 2, //禁止给类赋值
'no-cond-assign': 2, //禁止在条件表达式中使用赋值语句
'no-const-assign': 2, //禁止修改const声明的变
'no-delete-var': 2, //不能对var声明的变量使用delete操作符
'no-dupe-args': 2, //函数参数不能重复
'no-dupe-class-members': 2, // 此规则旨在标记在级别成员中使用重复名称。
'no-dupe-keys': 2, //在创建对象字面量时不允许键重复 {a:1,a:1}
'no-duplicate-case': 2, //switch中的case标签不能重复
'no-empty-character-class': 2, //正则表达式中的[]内容不能为空
'no-empty-pattern': 2, // 不能空解构,可以默认赋值
'no-ex-assign': 2, //禁止给catch语句中的异常参数赋值
'no-extend-native': 2, //禁止扩展native对象
'no-extra-bind': 2, //禁止不必要的函数绑定
'no-extra-boolean-cast': 2, //禁止不必要的bool转换
'no-extra-parens': [2, 'functions'], //禁止非必要的括号
'no-floating-decimal': 2, //禁止省略浮点数中的0 .5 3
'no-func-assign': 2, //禁止重复的函数声明
'no-implied-eval': 2, //禁止使用隐式eval
'no-inner-declarations': [2, 'functions'], //禁止在块语句中使用声明(变量或函数)
'no-invalid-regexp': 2, //禁止无效的正则表达式
'no-irregular-whitespace': 2, //不能有不规则的空格
'no-iterator': 2, //禁止使用__iterator__ 属性
'no-label-var': 2, //label名不能与var声明的变量名相同
'no-labels': [2, { //禁止标签声明
'allowLoop': false,
'allowSwitch': false
}],
'no-lone-blocks': 2, //禁止不必要的嵌套块
'no-mixed-spaces-and-tabs': 2, //禁止混用tab和空格
'no-multi-spaces': 2, // 没有多余的空格
'no-multi-str': 2, //字符串不能用\换行
'no-multiple-empty-lines': [2, { //空行最多不能超过2行
'max': 1
}],
'no-native-reassign': 2, //不能重写native对象
'no-negated-in-lhs': 2, //in 操作符的左边不能有!
'no-new-object': 2, // /禁止使用new Object()
'no-new-require': 2, //禁止使用new require
'no-new-wrappers': 2, //禁止使用new创建包装实例,new String new Boolean new Number
'no-obj-calls': 2, //不能调用内置的全局对象,比如Math() JSON()
'no-octal': 2, //禁止使用八进制数字
'no-octal-escape': 2, //禁止使用八进制转义序列
'no-path-concat': 2, //禁止给参数重新赋值
'no-proto': 2, //禁止使用__proto__属性
'no-redeclare': 2, //禁止重复声明变量
'no-regex-spaces': 2, //禁止在正则表达式字面量中使用多个空格 /foo bar/
'no-return-assign': [2, 'except-parens'], // return 赋值除非用圆括号括起来,否则不允许赋值。
'no-self-compare': 2, //不能比较自身
'no-shadow-restricted-names': 2, //严格模式中规定的限制标识符不能作为声明时的变量名使用
'no-spaced-func': 2,//函数调用时 函数名与()之间不能有空格
'no-sparse-arrays': 2, //禁止稀疏数组, [1,,2]
'no-throw-literal': 2, //禁止抛出字面量错误 throw "error";
'no-trailing-spaces': 2, // 一行结束后带有一个空格
'no-undef': 2,
'no-undef-init': 2, //变量初始化时不能直接给它赋值为undefined
'no-unexpected-multiline': 2, //避免多行表达式
'no-unneeded-ternary': [2, { // 当存在更简单的选择时,此规则不允许三元运算符。
'defaultAssignment': false
}],
'no-unreachable': 2, //不能有无法执行的代码
'no-unused-vars': [2, { //不能有声明后未被使用的变量或参数
'vars': 'all',
'args': 'none'
}],
'no-useless-call': 2, //禁止不必要的call和apply
'no-useless-computed-key': 2, // 没有必要使用带文字的计算属性
'no-useless-escape': 0, // 转义字符串
'no-whitespace-before-property': 2, // 如果对象的属性位于同一行上,则该规则不允许围绕点或在开头括号之前留出空白。当对象和属性位于不同的行上时,此规则允许使用空格,
'no-with': 2, // //禁用with
'one-var': [2, { //连续声明
'initialized': 'never'
}],
'operator-linebreak': [2, 'after', { //换行时运算符在行尾还是行首
'overrides': {
'?': 'before',
':': 'before'
}
}],
'padded-blocks': [2, 'never'], //块语句内行首行尾是否要空行
'quotes': [2, 'single', { //引号类型 `` "" ''
'avoidEscape': true,
'allowTemplateLiterals': true
}],
'semi': [2, 'never'], // 不使用分号
'semi-spacing': [2, { // 禁止或强制使用分号周围的空格可以提高程序的可读性
'before': false,
'after': true
}],
'space-before-blocks': [2, 'always'], //此规则将强化块之前的间距一致性
'space-before-function-paren': [2, 'never'], //函数定义时括号前面要不要有空格
'space-in-parens': [2, 'never'], //小括号里面要不要有空格
'space-infix-ops': 2, //中缀操作符周围要不要有空格
'space-unary-ops': [2, { //一元运算符的前/后要不要加空格
'words': true,
'nonwords': false
}],
'spaced-comment': [2, 'always', { //注释风格要不要有空格什么的
'markers': ['global', 'globals', 'eslint', 'eslint-disable', '*package', '!', ',']
}],
'template-curly-spacing': [2, 'never'], //此规则旨在保持模板文字内部空间的一致性
'use-isnan': 2, //禁止比较时使用NaN,只能用isNaN()
'valid-typeof': 2, //必须使用合法的typeof的值
'wrap-iife': [2, 'any'], //立即执行函数表达式的小括号风格
'yield-star-spacing': [2, 'both'], // 规则强制执行*周围 yield*表达式的间距
'yoda': [2, 'never'], // 强制执行一种将变量与文字值进行比较的一致条件样式
'prefer-const': 2, // 标记使用let关键字声明的变量,但在初始分配后从未重新分配变量。
'no-debugger': process.env.NODE_ENV === 'production' ? 2 : 0, // 此规则不允许debugger声明。 本地开发可以,环境上不行
'object-curly-spacing': [2, 'always', { // 规则在对象文字的大括号内执行一致的间距,解构赋值和导入/导出说明符。
objectsInObjects: false
}],
'array-bracket-spacing': [2, 'never'] // 规则在数组括号内强制实现一致的间距。
}
}
关于Eslint配置项解析
最新推荐文章于 2024-05-30 11:27:58 发布