安装
npm install eslint --save-dev
npm install eslint --global #全局安装
# 设置配置文件
./node_modules/.bin/eslint --init
# 可以单独运行在一个指定文件 或者目录上面
./node_modules/.bin/eslint yourfile.js
# 初始化
vue
// eslint-disable-next-line no-undef
module.exports = {
'env': {
'browser': true,
'es2021': true
},
'extends': [
'eslint:recommended',
'plugin:vue/essential'
],
'parserOptions': {
'ecmaVersion': 12,
'sourceType': 'module'
},
'plugins': ['vue'],
'rules': {
'for-direction': 'error',
'no-cond-assign': 'error',
'array-bracket-newline': 0,
'array-bracket-spacing': 'error',
'array-callback-return': 'error',
'callback-return': 'error',
'array-element-newline': 0,
'arrow-spacing': 'error',
'block-scoped-var': 'error',
'block-spacing': 'error',
'brace-style': 'error',
'capitalized-comments': 0,
'comma-dangle': 0,
'comma-style': 2,
'comma-spacing': 'error',
'complexity': 'error',
'computed-property-spacing': 'error',
'consistent-return': 'error',
'consistent-this': 'error',
'curly': 'error',
'default-case': 'error',
'default-case-last': 'error',
'default-param-last': 'error',
'dot-location': 'error',
'dot-notation': 'error',
'eol-last': 'error',
'eqeqeq': 'error',
'func-call-spacing': 'error',
'func-name-matching': 'error',
'func-names': 'error',
'function-paren-newline': 'error',
'guard-for-in': 'error',
'implicit-arrow-linebreak': 'error',
'indent': ['error', 2, { 'ignoreComments': true }],
'init-declarations': 'error',
'no-delete-var': 'error',
'jsx-quotes': ['error', 'prefer-double'],
'key-spacing': 'error',
'keyword-spacing': ['error', { 'after': true, 'before': true}],
'line-comment-position': ['error', { 'before': true }],
'linebreak-style': [ 'error','unix'],
'lines-around-comment': 'error',
'lines-between-class-members': 'error',
'no-class-assign': 'error',
'max-classes-per-file': 'error',
'max-depth': 'error',
'max-len': 'error',
'multiline-comment-style': 'error',
'new-cap': 'error',
'new-parens': 'error',
'newline-per-chained-call': 'error',
'no-mixed-requires': 0,
'no-restricted-modules': 0,
'no-compare-neg-zero': 'error',
'no-confusing-arrow': 'error',
'no-case-declarations': 'error',
'no-dupe-args': 'error',
'no-dupe-keys': 'error',
'no-duplicate-case': 'error',
'no-empty': 'error',
'no-empty-character-class': 'error',
'no-duplicate-imports': 'error',
'no-new-symbol': 'error',
'no-else-return': 'error',
'no-empty-function': 'error',
'no-empty-pattern': 'error',
'no-eq-null': 'error',
'no-eval': 'error',
'no-extra-label': 'error',
'no-fallthrough': 'error',
'no-extra-semi': 'error',
'no-func-assign': 'error',
'no-inner-declarations': 'error',
'no-invalid-regexp': 'error',
'no-irregular-whitespace': 'error',
'no-obj-calls': 'error',
'no-regex-spaces': 'error',
'no-floating-decimal': 'error',
'no-global-assign': 'error',
'no-lonely-if': 'error',
'no-loop-func': 'error',
'no-loss-of-precision': 'error',
'no-magic-numbers': 'error',
'no-multiple-empty-lines': 'error',
'no-redeclare': 'error',
'no-return-assign': 'error',
'no-self-assign': 'error',
'no-self-compare': 'error',
'no-sequences': 'error',
'no-shadow': 'error',
'no-tabs': 'off',
'no-shadow-restricted-names': 'error',
'no-unexpected-multiline': 'error',
'no-unreachable': 'error',
'no-unsafe-finally': 'error',
'no-unsafe-negation': 'error',
'no-undef': 'error',
'no-undef-init': 'error',
'no-undefined': 'error',
'no-unused-vars': 'error',
'no-underscore-dangle': 'error',
'no-unmodified-loop-condition': 'error',
'no-unneeded-ternary': 'error',
'no-unreachable-loop': 'error',
'no-unsafe-optional-chaining': 'error',
'no-unused-expressions': 'error',
'no-unused-labels': 'error',
'no-use-before-define': 'error',
'no-useless-catch': 'error',
'no-useless-computed-key': 'error',
'no-useless-escape': 'error',
'no-useless-constructor': 'error',
'no-useless-rename': 'error',
'no-useless-return': 'error',
'no-var': 'error',
'no-whitespace-before-property': 'error',
'nonblock-statement-body-position': 'error',
'object-curly-newline': 'error',
'object-property-newline': 0,
'object-shorthand': 'error',
'one-var': 'off',
'one-var-declaration-per-line': 'error',
'operator-assignment': 'error',
'operator-linebreak': 'error',
'padded-blocks': 'error',
'padding-line-between-statements': 'error',
'prefer-arrow-callback': 'error',
'prefer-const': 'error',
'no-const-assign': 'error',
'no-dupe-class-members': 'error',
'prefer-destructuring': 'error',
'prefer-object-spread': 'error',
'prefer-template': 'error',
'quotes': [
'error',
'single'
],
'use-isnan': 'error',
'valid-typeof': 'error',
'require-await': 'error',
'semi': 'off',
'sort-imports': 'error',
'semi-spacing': 'error',
'semi-style': 'error',
'sort-vars': 'error',
'space-before-blocks': 'error',
'space-before-function-paren': 'error',
'space-in-parens': [
'error',
'never'
],
'space-infix-ops': 'error',
'space-unary-ops': 'error',
'spaced-comment': 'error',
'strict': 'off',
'unicode-bom': 'error',
'switch-colon-spacing': 'error'
}
};
.eslintrc.js文件配置
/*
*@author Augo
* 单行注释 推荐的规则
* 多行注释 推荐可选
* global
*/
/* @global */
module.exports = {
'root': true,
// 指定环境
'env': {
'browser': true,
// 'es2021': true,
'es6': true,
'node': true
},
'extends': [
'plugin:vue/essential',
'standard'
/*
* 'eslint:recommended',
*
*/
// 'plugin:vue/vue3-recommended'
/*
*
* 'plugin:vue/essential',
*
*/
],
// 'parser': 'babel-eslint',
// 指定解析器选项
'parserOptions': {
'parser': 'babel-eslint',
/*
*
* 设置为 3、5(默认)、6、7、8、9、10、11 或 12 以指定要使用的 ECMAScript 语法版本
*/
'ecmaVersion': 6,
// 设置为"script"(默认)或者"module"如果您的代码在 ECMAScript 模块中
'sourceType': 'module'
/*
* 一个对象,指示您要使用哪些附加语言功能
* 'ecmaFeatures': {
* 'jsx': true
* // 'experimentalObjectRestSpread': true
* }
*/
},
// 使用插件
'plugins': ['vue'],
// 配置规则
'rules': {
/*
* Vue3 的校验配置
* allow async-await
*/
'generator-star-spacing': 'off',
// Allow debugger during development
'vue/no-use-v-if-with-v-for': [
'error', {
'allowUsingIterationVar': false
}
],
'vue/return-in-computed-property': [
'error', {
'treatUndefinedAsUnspecified': false
}
],
'vue/no-unused-components': [
'error', {
'ignoreWhenBindingPresent': true
}
],
'vue/attribute-hyphenation': [
'error', 'always', {
'ignore': []
}
],
'vue/component-name-in-template-casing': [
'error', 'kebab-case', {
'ignores': []
}
],
'vue/html-closing-bracket-newline': [
'error', {
'singleline': 'never',
'multiline': 'always'
}
],
'vue/html-closing-bracket-spacing': [
'error', {
'startTag': 'never',
'endTag': 'never',
'selfClosingTag': 'always'
}
],
'vue/html-indent': [
'error', 2, {
'attribute': 1,
'baseIndent': 1,
'closeBracket': 0,
'alignAttributesVertically': true,
'ignores': []
}
],
'vue/html-quotes': ['error', 'double'],
'vue/html-self-closing': [
'error', {
'html': {
'void': 'never',
'normal': 'never',
'component': 'always'
},
'svg': 'always',
'math': 'always'
}
],
'vue/max-attributes-per-line': [
'error', {
'singleline': {
'max': 3,
'allowFirstLine': true
},
'multiline': {
'max': 3,
'allowFirstLine': true
}
}
],
'vue/multiline-html-element-content-newline': [
'error', {
'ignoreWhenEmpty': true,
'ignores': ['pre', 'textarea']
}
],
'vue/mustache-interpolation-spacing': ['error', 'always'],
'vue/name-property-casing': ['error', 'kebab-case'],
'vue/no-multi-spaces': [
'error', {
'ignoreProperties': false
}
],
'vue/no-spaces-around-equal-signs-in-attribute': ['error'],
'vue/no-template-shadow': ['error'],
'vue/prop-name-casing': ['error', 'camelCase'],
'vue/require-default-prop': ['error'],
'vue/v-bind-style': ['error', 'shorthand'],
'vue/v-on-style': ['error', 'shorthand'],
'vue/attributes-order': [
'error', {
'order': [
'DEFINITION',
'LIST_RENDERING',
'CONDITIONALS',
'RENDER_MODIFIERS',
'GLOBAL',
'UNIQUE',
'TWO_WAY_BINDING',
'OTHER_DIRECTIVES',
'OTHER_ATTR',
'EVENTS',
'CONTENT'
]
}
],
'vue/order-in-components': [
'error', {
'order': [
'el',
'name',
'parent',
'functional',
['delimiters', 'comments'],
['components', 'directives', 'filters'],
'extends',
'mixins',
'inheritAttrs',
'model',
['props', 'propsData'],
'data',
'computed',
'watch',
'LIFECYCLE_HOOKS',
'methods',
['template', 'render'],
'renderError'
]
}
],
'vue/this-in-template': ['error', 'never'],
// * 强制 “for” 循环中更新子句的计数器朝着正确的方向移动
'for-direction': 'error',
//* * 禁止条件表达式中出现赋值操作符
'no-cond-assign': 'error',
/*
* 强制 getter 和 setter 在对象中成对出现
* 'accessor-pairs': 'error',
*/
// 禁止使用异步函数作为 Promise executorrules
'no-async-promise-executor': 'error',
// 在数组开括号后和闭括号前强制换行
'array-bracket-newline': 'error',
// 强制数组方括号中使用一致的空格
'array-bracket-spacing': 'error',
// 强制数组方法的回调函数中有 return 语句
'array-callback-return': 'error',
/*
* 强制数组方法的回调函数中有 return 语句
* 'callback-return': 'error',
*/
/*
* 要求回调函数中有容错处理
* 'handle-callback-err': 'error',
*/
/*
* 强制数组元素间出现换行
* 'array-element-newline': 'error',
*/
/*
* 要求箭头函数体使用大括号
* 'arrow-body-style': 'error',
*/
// 要求箭头函数的参数使用圆括号
'arrow-parens': [
'error',
'as-needed'
],
// 强制箭头函数的箭头前后使用一致的空格
'arrow-spacing': 'error',
// 强制把变量的使用限制在其定义的作用域范围内
'block-scoped-var': 'error',
// 禁止或强制在代码块中开括号前和闭括号后有空格
'block-spacing': 'error',
// 强制在代码块中使用一致的大括号风格
'brace-style': 'error',
/*
* 强制使用骆驼拼写法命名约定
* 'camelcase': 'error',
*/
// 强制或禁止对注释的第一个字母大写
'capitalized-comments': 'error',
// 强制类方法使用 this
'class-methods-use-this': 'error',
// 要求或禁止末尾逗号
'comma-dangle': 'error',
/*
* 强制在逗号前后使用一致的空格
* 'comma-spacing': 'error',
*/
/*
* 强制使用一致的逗号风格
* 'comma-style': 'error',
*/
/*
* 指定程序中允许的最大环路复杂度
* 'complexity': 'error',
*/
// 强制在计算的属性的方括号中使用一致的空格
'computed-property-spacing': 'error',
// 要求 return 语句要么总是指定返回的值,要么不指定
'consistent-return': 'error',
/*
* 当获取当前执行环境的上下文时,强制使用一致的命名
* 'consistent-this': 'error',
*/
/*
* 强制所有控制语句使用一致的括号风格
* 'curly': 'error',
*/
// 要求 switch 语句中有 default 分支
'default-case': 'error',
/*
* 最后一个默认案例
* 'default-case-last': 'error',
*/
/*
* 默认参数last
* 'default-param-last': 'error',
*/
// 强制在点号之前和之后一致的换行
'dot-location': 'error',
// 强制尽可能地使用点号
'dot-notation': 'error',
// 要求或禁止文件末尾存在空行
'eol-last': 'error',
// 要求使用 === 和 !==
'eqeqeq': 'error',
// 要求或禁止在函数标识符和其调用之间有空格
'func-call-spacing': 'error',
/*
* 要求函数名与赋值给它们的变量名或属性名相匹配
* 'func-name-matching': 'error',
*/
/*
* 要求或禁止使用命名的 function 表达式
* 'func-names': 'error',
*/
/*
* 强制一致使用function声明或表达式
* 'func-style': 'error',
*/
/*
* 函数调用参数换行符
* 'function-call-argument-newline': 'error',
*/
/*
* 强制在函数括号内使用一致的换行
* 'function-paren-newline': 'error',
*/
/*
* 禁用指定的标识符
* 'id-blacklist': 'error',
*/
/*
* 强制 generator 函数中 * 号周围使用一致的空格
* 'generator-star-spacing': 'error',
*/
/*
* 分组存取器对
* 'grouped-accessor-pairs': 'error',
*/
/*
* 要求 for-in 循环中有一个 if 语句
* 'guard-for-in': 'error',
*/
// 'id-denylist': 'error',
/*
* 强制标识符的最小和最大长度
* 'id-length': 'error',
*/
/*
* 要求标识符匹配一个指定的正则表达式
* 'id-match': 'error',
*/
// 强制隐式返回的箭头函数体的位置
'implicit-arrow-linebreak': 'error',
// 强制使用一致的缩进 缩进 2空格 ignoreComments (默认: false) 当注释不需要与前一行或下一行的注释对齐,可以使用此选项
'indent': ['error', 2, { 'ignoreComments': true }],
/*
* 要求或禁止 var 声明中的初始化
* 'init-declarations': 'error',
*/
// 禁止删除变量
'no-delete-var': 'error',
/*
* 该规则强制在 JSX 属性中使用一致的单引号或双引号。
* "prefer-double" (默认) 强制所有不包含双引号的 JSX 属性值使用双引号。
* "prefer-single" 强制所有不包含单引号的 JSX 属性值使用单引号。
*/
'jsx-quotes': ['error', 'prefer-double'],
// 强制在对象字面量的属性中键和值之间使用一致的间距
'key-spacing': 'error',
// 强制在关键字前后使用一致的空格
'keyword-spacing': [
'error',
{
'after': true,
'before': true
}
],
/*
*
* 强制行注释的位置
* 'line-comment-position': ['error', { 'before': true }],
*/
// 强制使用一致风格
'linebreak-style': [
'error',
// "windows"
'unix'
],
// 要求注释周围有空格
'lines-around-comment': 'error',
// 要求或禁止类成员之间出现空行
'lines-between-class-members': 'error',
// 禁止修改类声明的变量
'no-class-assign': 'error',
/*
* 强制每个文件中包含的的类的最大数量
* 'max-classes-per-file': 'error',
*/
/*
* 强制可嵌套的块的最大深度
* 'max-depth': 'error',
*/
/*
* 强制一行的最大长度
* 'max-len': 'error',
*/
/*
* 强制最大文件长度
* "code"(默认80)强制最大行长度
* "tabWidth"(默认4)指定制表符的字符宽度
* "comments"强制注释的最大行长;默认值为code
* "ignorePattern"忽略匹配正则表达式的行;只能匹配一行,用YAML或JSON编写时需要双重转义
* "ignoreComments": true 忽略所有尾随注释和它们自己行的注释
* "ignoreTrailingComments": true 仅忽略尾随评论
* "ignoreUrls": true 忽略包含 URL 的行
* "ignoreStrings": true 忽略包含双引号或单引号字符串的行
* "ignoreTemplateLiterals": true 忽略包含模板文字的行
* "ignoreRegExpLiterals": true 忽略包含 RegExp 文字的行
*/
/*
* 'max-lines': [
* 'error',
* {
* 'max': 500,
* 'skipComments': true,
* 'skipBlankLines': true
* }
* ],
*/
/*
* 强制函数最大代码行数
* 'max-lines-per-function': 'error',
*/
/*
* 强制回调函数最大嵌套深度
* 'max-nested-callbacks': 'error',
*/
/*
* 强制函数定义中最多允许的参数数量
* 'max-params': 'error',
*/
/*
* 强制函数块最多允许的的语句数量
* 'max-statements': 'error',
*/
/*
* 强制每一行中所允许的最大语句数量
* 'max-statements-per-line': 'error',
*/
// 强制对多行注释使用特定风格
'multiline-comment-style': 'error',
/*
* 要求或禁止在三元操作数中间换行
* 'multiline-ternary': 'error',
*/
// 要求构造函数首字母大写
'new-cap': 'error',
// 强制或禁止调用无参构造函数时有圆括号
'new-parens': 'error',
// 要求方法链中每个调用都有一个换行符
'newline-per-chained-call': 'error',
/*
* 禁用 alert、confirm 和 prompt
* 'no-alert': 'error',
*/
/*
* 禁用 Array 构造函数
* 'no-array-constructor': 'error',
*/
// 禁用 Buffer() 构造函数
'no-buffer-constructor': 'error',
/*
* 禁止混合常规变量声明和 require 调用
* 'no-mixed-requires': 'error',
*/
/*
* 禁止调用 require 时使用 new 操作符
* 'no-new-require': 'error',
*/
/*
* 禁止对 __dirname 和 __filename 进行字符串连接
* 'no-path-concat': 'error',
*/
/*
* 禁用 process.env
* 'no-process-env': 'error',
*/
/*
* 禁用 process.exit()
* 'no-process-exit': 'error',
*/
/*
* 禁用通过 require 加载的指定模块
* 'no-restricted-modules': 'error',
*/
/*
* 禁用同步方法
* 'no-sync': 'error',
*/
// 禁止在循环中出现 await
'no-await-in-loop': 'error',
// 禁止与 -0 进行比较
'no-compare-neg-zero': 'error',
/*
* 禁用按位运算符
* 'no-bitwise': 'error',
*/
/*
* 禁用 arguments.caller 或 arguments.callee
* 'no-caller': 'error',
*/
// 禁止在可能与比较操作符相混淆的地方使用箭头函数
'no-confusing-arrow': 'error',
// 不允许在 case 子句中使用词法声明
'no-case-declarations': 'error',
/*
* 禁用 console
* 'no-console': 'error',
*/
// 禁止在条件中使用常量表达式
'no-constant-condition': 'error',
// 禁止在正则表达式中使用控制字符
'no-control-regex': 'error',
// 禁用 debugger
'no-debugger': 'error',
// 禁止 function 定义中出现重名参数
'no-dupe-args': 'error',
// 禁止对象字面量中出现重复的 key
'no-dupe-keys': 'error',
// 禁止出现重复的 case 标签
'no-duplicate-case': 'error',
// 禁止出现空语句块
'no-empty': 'error',
// /禁止在正则表达式中使用空字符集
'no-empty-character-class': 'error',
// 禁止对 catch 子句的参数重新赋值
'no-ex-assign': 'error',
// 禁止不必要的布尔转换
'no-extra-boolean-cast': 'error',
/*
* 无构造函数返回
* 'no-constructor-return': 'error',
*/
/*
* 要求在构造函数中有 super() 的调用
* 'constructor-super': 'error',
*/
// 禁用 continue 语句
'no-continue': 'error',
// 禁止除法操作符显式的出现在正则表达式开始的位置
'no-div-regex': 'error',
// 禁止重复模块导入
'no-duplicate-imports': 'error',
// 禁止 Symbolnew 操作符和 new 一起使用
'no-new-symbol': 'error',
// 禁止 if 语句中 return 语句之后有 else 块
'no-else-return': 'error',
// 禁止出现空函数
'no-empty-function': 'error',
// 禁止使用空解构模式
'no-empty-pattern': 'error',
// 禁止在没有类型检查操作符的情况下与 null 进行比较
'no-eq-null': 'error',
// 禁用 eval()
'no-eval': 'error',
// 禁止扩展原生类型
'no-extend-native': 'error',
// 禁止不必要的 .bind() 调用
'no-extra-bind': 'error',
// 禁用不必要的标签
'no-extra-label': 'error',
// 禁止 case 语句落空
'no-fallthrough': 'error',
/*
* 禁止不必要的括号
* 'no-extra-parens': 'error',
*/
// 禁止不必要的分号
'no-extra-semi': 'error',
// 禁止对 function 声明重新赋值
'no-func-assign': 'error',
// 禁止在嵌套的块中出现变量声明或 function 声明
'no-inner-declarations': 'error',
// 禁止 RegExp 构造函数中存在无效的正则表达式字符串
'no-invalid-regexp': 'error',
// 禁止不规则的空白
'no-irregular-whitespace': 'error',
// 不允许在字符类语法中出现由多个代码点组成的字符
'no-misleading-character-class': 'error',
// 禁止把全局对象作为函数调用
'no-obj-calls': 'error',
// 禁止直接调用 Object.prototypes 的内置属性
'no-prototype-builtins': 'error',
// 禁止正则表达式字面量中出现多个空格
'no-regex-spaces': 'error',
// 禁用稀疏数组
'no-sparse-arrays': 'error',
// 禁止数字字面量中使用前导和末尾小数点 错误的 .5 真确的 0.5
'no-floating-decimal': 'error',
// 禁止对原生对象或只读的全局对象进行赋值
'no-global-assign': 'error',
// 禁止使用短符号进行类型转换
'no-implicit-coercion': 'error',
/*
* 禁止在全局范围内使用变量声明和 function 声明
* 'no-implicitrules-globals': 'error',
*/
/*
* 禁止使用类似 eval() 的方法
* 'no-implied-eval': 'error',
*/
/*
* 禁止在代码后使用内联注释
* 'no-inline-comments': 'error',
*/
// 禁止 this 关键字出现在类和类对象之外
'no-invalid-this': 'error',
// 禁用 __iterator__ 属性
'no-iterator': 'error',
/*
* 不允许标签与变量同名
* 'no-label-var': 'error',
*/
// 禁用标签语句
'no-labels': 'error',
// 禁用不必要的嵌套块
'no-lone-blocks': 'error',
/*
* 禁止 if 作为唯一的语句出现在 else 语句中
* 'no-lonely-if': 'error',
*/
// 禁止在循环语句中出现包含不安全引用的函数声明
'no-loop-func': 'error',
/*
* 无精度损失
* 'no-loss-of-precision': 'error',
*/
/*
* 禁用魔术数字
* 'no-magic-numbers': 'error',
*/
/*
* 禁止混合使用不同的操作符
* 'no-mixed-operators': 'error',
*
*/
/*
* 禁止连续赋值
* 'no-multi-assign': 'error',
*/
/*
* 禁止空格和 tab 的混合缩进
* 'no-mixed-spaces-and-tabs': 'error',
*/
// 禁止使用多个空格
'no-multi-spaces': 'error',
// 禁止使用多行字符串
'no-multi-str': 'error',
// 禁止出现多行空行
'no-multiple-empty-lines': 'error',
/*
* 禁用否定的表达式
* 'no-negated-condition': 'error',
*/
/*
* 禁用嵌套的三元表达式
* 'no-nested-ternary': 'error',
*/
// 禁止使用 new 以避免产生副作用
'no-new': 'error',
// 禁止对 Function 对象使用 new 操作符
'no-new-func': 'error',
// 禁止对 object 对象使用 new 操作符
'no-new-object': 'error',
// 禁止对 String,Number 和 Boolean 使用 new 操作符
'no-new-wrappers': 'error',
/*
* 无非八进制十进制转义
* 'no-nonoctal-decimal-escape': 'error',
*/
// 禁用八进制字面量
'no-octal': 'error',
// 禁止在字符串中使用八进制转义序列
'no-octal-escape': 'error',
// 禁止对 function 的参数进行重新赋值
'no-param-reassign': 'error',
// 禁用一元操作符 ++ 和 --
'no-plusplus': 'error',
/*
* 无承诺执行人返回
* 'no-promise-executor-return': 'error',
*/
// 禁用 __proto__ 属性
'no-proto': 'error',
// 禁止多次声明同一变量
'no-redeclare': 'error',
/*
* 没有限制出口
* 'no-restricted-exports': 'error',
*/
/*
* 禁用特定的全局变量
* 'no-restricted-globals': 'error',
*/
/*
* 禁止使用指定的 import 加载的模块
* 'no-restricted-imports': 'error',
*/
/*
* 禁止在构造函数中,在调用 super() 之前使用 this 或 super
* 'no-this-before-super': 'error',
*/
/*
* 禁止使用对象的某些属性
* 'no-restricted-properties': 'error',
*/
/*
* 禁用特定的语法
* 'no-restricted-syntax': 'error',
*/
// 禁止在 return 语句中使用赋值语句
'no-return-assign': 'error',
// 禁用不必要的 return await
'no-return-await': 'error',
// 禁止使用 javascript: url
'no-script-url': 'error',
// 禁止自我赋值
'no-self-assign': 'error',
// 禁止自身比较
'no-self-compare': 'error',
// 禁用逗号操作符
'no-sequences': 'error',
/*
* 禁止变量声明与外层作用域的变量同名
* 'no-shadow': 'error',
*/
/*
* 禁用 tab
* 'no-tabs': 'off',
*/
'no-tabs': 'off',
// 禁止将标识符定义为受限的名字
'no-shadow-restricted-names': 'error',
/*
* 禁止在常规字符串中出现模板字面量占位符语法
* 'no-template-curly-in-string': 'error',
*/
// 禁止出现令人困惑的多行表达式
'no-unexpected-multiline': 'error',
// 禁止在 return、throw、continue 和 break 语句之后出现不可达代码
'no-unreachable': 'error',
// 禁止在 finally 语句块中出现控制流语句
'no-unsafe-finally': 'error',
// 禁止对关系运算符的左操作数使用否定操作符
'no-unsafe-negation': 'error',
/*
* 禁用三元操作符
* 'no-ternary': 'error',
*/
// 禁止抛出异常字面量
'no-throw-literal': 'error',
// 禁用行尾空格
'no-trailing-spaces': 'error',
/*
* 禁用未声明的变量,除非它们在 global 注释中被提到
* 'no-undef': 'error',
*
*/
// 禁止将变量初始化为 undefined
'no-undef-init': 'error',
// 禁止将 undefined 作为标识符
'no-undefined': 'error',
// 禁止出现未使用过的变量
'no-unused-vars': 'error',
// 禁止标识符中有悬空下划线
'no-underscore-dangle': 'error',
// 禁用一成不变的循环条件
'no-unmodified-loop-condition': 'error',
// 禁止可以在有更简单的可替代的表达式时使用三元操作符
'no-unneeded-ternary': 'error',
/*
* 没有无法到达的循环
* 'no-unreachable-loop': 'error',
*/
/*
* 没有不安全的可选链接
* 'no-unsafe-optional-chaining': 'error',
*/
// 禁止出现未使用过的表达式
'no-unused-expressions': 'error',
// 禁用出现未使用过的标
'no-unused-labels': 'error',
// 禁止在变量定义之前使用它们
'no-use-before-define': 'error',
/*
* 沒找到 自动生成的 个人理解 没有无用的反向引用
* 'no-useless-backreference': 'error',
*/
/*
* 禁止不必要的 .call() 和 .apply()
* 'no-useless-call': 'error',
*/
// 禁止不必要的 catch 子句
'no-useless-catch': 'error',
// 禁止在对象中使用不必要的计算属性
'no-useless-computed-key': 'error',
/*
* 禁止不必要的字符串字面量或模板字面量的连接
* 'no-useless-concat': 'error',
*/
// 禁用不必要的转义字符
'no-useless-escape': 'error',
// 禁用不必要的构造函数
'no-useless-constructor': 'error',
// 禁止在 import 和 export 和解构赋值时将引用重命名为相同的名字
'no-useless-rename': 'error',
// 禁止多余的 return 语句
'no-useless-return': 'error',
// 要求使用 let 或 const 而不是 var
'no-var': 'error',
/*
* 禁用 void 操作符
* 'no-void': 'error',
*/
/*
* 禁止在注释中使用特定的警告术语
* 'no-warning-comments': 'error',
*/
/*
* 禁用 with 语句
* 'no-with': 'error',
*/
// 禁止属性前有空白
'no-whitespace-before-property': 'error',
// 强制单个语句的位置
'nonblock-statement-body-position': 'error',
// 强制大括号内换行符的一致性
'object-curly-newline': 'error',
/*
* 强制在大括号中使用一致的空格
* 'object-curly-spacing': [
* 'error',
* 'error'
* ],
*/
// 强制将对象的属性放在不同的行上
'object-property-newline': 'error',
// 要求或禁止对象字面量中方法和属性使用简写语法
'object-shorthand': 'error',
// 强制函数中的变量要么一起声明要么分开声明
'one-var': 'off',
// 要求或禁止在变量声明周围换行
'one-var-declaration-per-line': 'error',
// 要求或禁止在可能的情况下使用简化的赋值操作符
'operator-assignment': 'error',
// 强制操作符使用一致的换行符
'operator-linebreak': 'error',
// 要求或禁止块内填充
'padded-blocks': 'error',
// 要求或禁止在语句间填充空行
'padding-line-between-statements': 'error',
// 要求回调函数使用箭头函数
'prefer-arrow-callback': 'error',
// 要求使用 const 声明那些声明后不再被修改的变量
'prefer-const': 'error',
// 禁止修改 const 声明的变量
'no-const-assign': 'error',
// 禁止类成员中出现重复的名称
'no-dupe-class-members': 'error',
// 优先使用数组和对象解构
'prefer-destructuring': 'error',
/*
* 求幂运算符
* 'prefer-exponentiation-operator': 'error',
*/
/*
* 建议在正则表达式中使用命名捕获组
* 'prefer-named-capture-group': 'error',
*/
/*
* 禁用 parseInt() 和 Number.parseInt(),使用二进制,八进制和十六进制字面量
* 'prefer-numeric-literals': 'error',
*/
// 禁止使用以对象字面量作为第一个参数的 Object.assign,优先使用对象扩展。
'prefer-object-spread': 'error',
/*
* 要求使用 Error 对象作为 Promise 拒绝的原因
* 'prefer-promise-reject-errors': 'error',
*/
/*
* 正则
* 'prefer-regex-literals': 'error',
*/
// 要求 generator 函数内有 yield
'require-yield': 'error',
/*
* 要求使用剩余参数而不是 arguments
* 'prefer-rest-params': 'error',
*/
/*
* 要求使用扩展运算符而非 .apply()
* 'prefer-spread': 'error',
*/
// 要求使用模板字面量而非字符串连接
'prefer-template': 'error',
/*
* 要求对象字面量属性名称用引号括起来
* 'quote-props': 'error',
*/
// 强制使用一致的反勾号、双引号或单引号
'quotes': [
'error',
'single'
],
/*
* 强制在 parseInt() 使用基数参数
* 'radix': 'error',
*/
// 禁止由于 await 或 yield的使用而可能导致出现竞态条件的赋值
'require-atomic-updates': 'error',
/*
* 要求 require() 出现在顶层模块作用域中
* 'global-require': 'error',
*/
// 要求使用 isNaN() 检查 NaN
'use-isnan': 'error',
// 强制 typeof 表达式与有效的字符串进行比较
'valid-typeof': 'error',
/*
* 禁止使用不带 await 表达式的 async 函数
* 'require-await': 'error',
*/
/*
* 强制在 RegExp 上使用 u 标志
* 'require-unicode-regexp': 'error',
*/
// 强制剩余和扩展运算符及其表达式之间有空格
'rest-spread-spacing': 'error',
// 要求或禁止使用分号代替 ASI
'semi': 'off',
/*
* 强制模块内的 import 字母排序
* 'sort-imports': 'error',
*/
// 强制分号之前和之后使用一致的空格
'semi-spacing': 'error',
// 强制分号的位置
'semi-style': 'error',
/*
* 对象按照字母排序
* 'sort-keys': 'error',
*/
// 要求同一个声明块中的变量按顺序排列
'sort-vars': 'error',
// 强制在块之前使用一致的空格
'space-before-blocks': 'error',
// 强制在 function的左括号之前使用一致的空格
'space-before-function-paren': 'error',
// 强制在圆括号内使用一致的空格
'space-in-parens': [
'error',
'never'
],
// 要求操作符周围有空格
'space-infix-ops': 'error',
// 强制在一元操作符前后使用一致的空格
'space-unary-ops': 'error',
// 强制在注释中 // 或 /* 使用一致的空格
'spaced-comment': 'error',
//* 要求或禁止使用严格模式指令
'strict': 'off',
// 要求或禁止在模板标记和它们的字面量之间有空格
'unicode-bom': 'error',
// 强制在 switch 的冒号左右有空格
'switch-colon-spacing': 'error',
/*
* 要求 symbol 描述
* 'symbol-description': 'error',
*/
// 要求或禁止模板字符串中的嵌入表达式周围空格的使用
'template-curly-spacing': 'error',
// 要求或禁止在模板标记和它们的字面量之间有空格
'template-tag-spacing': 'error',
/*
* 要求所有的 var 声明出现在它们所在的作用域顶部
* 'vars-on-top': 'error',
*/
// 要求 IIFE 使用括号括起来
'wrap-iife': 'error',
// 要求正则表达式被括号括起来
'wrap-regex': 'error',
// 强制在 yield* 表达式中 * 周围使用空格
'yield-star-spacing': 'error'
/*
* 要求或禁止 “Yoda” 条件
* 'yoda': 'error'
*/
/*
* 'singleQuote': 'error'
* 使用单引号, 默认false(在jsx中配置无效, 默认都是双引号)
*/
}
};
- 规则级别
"off"
or 0
- 关闭规则"warn"
or 1
- 将规则视为一个警告(不会影响退出码)"error"
or 2
- 将规则视为一个错误 (退出码为1)
具体规则介绍
https://eslint.bootcss.com/docs/user-guide/configuring#extending-configuration-files
https://eslint.bootcss.com/docs/rules/object-curly-spacing
配置vscode 自动格式化
setting.json
"editor.codeActionsOnSave": {
"source.fixAll": true,
"source.fixAll.eslint": true,
},
"eslint.format.enable": true,
忽略文件配置 .eslintignore
# 可以通过.eslintignore在项目的根目录中创建一个文件来告诉 ESLint 忽略特定的文件和目录
# *.js 忽略所有的 js文件