ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

eslint内置规则介绍

2021-12-18 23:30:21  阅读:232  来源: 互联网

标签:内置 off no rules eslint https 规则 options


内置规则

eslint 内置规则介绍

modules.exports = {
	// 所有规则页面(https://eslint.org/docs/rules)标记为 ✔ 的规则将会默认开启
  	extends: ['eslint:recommended'],
  	parserOptions: {
		ecmaVersion: 'latest',
    	sourceType: 'module',
	},
	/* Rules *代表recommended也就是'error', ()包裹代表可--fix自动修复, options代表有其它选项建议去官网查看用法, 还有这个规则适合什么时候使用的介绍 */
	rules: {
		/* Possible Problems: These rules relate to possible logic errors in code */
	    // options Array回调函数需要return  https://eslint.org/docs/rules/array-callback-return
	    'array-callback-return': [
	      'off',
	      { allowImplicit: false, checkForEach: false },
	    ],
	    // * 派生类的Constructor中调用super()
	    'constructor-super': 'error',
	    // * for循环方向错误导致终止条件无法到达
	    'for-direction': 'error',
	    // *options getter函数需要return  https://eslint.org/docs/rules/getter-return
	    'getter-return': ['error', { allowImplicit: false }],
	    // * 禁止使用async函数作为new Promise()的参数
	    'no-async-promise-executor': 'error',
	    // 禁止for循环中使用await
	    'no-await-in-loop': 'off',
	    // * 禁止修改class声明的变量
	    'no-class-assign': 'error',
	    // * 禁止与-0比较
	    'no-compare-neg-zero': 'error',
	    // *options 禁止测试条件中出现赋值操作符  https://eslint.org/docs/rules/no-cond-assign
	    'no-cond-assign': ['error', 'except-parens'],
	    // * 禁止修改const声明的变量
	    'no-const-assign': 'error',
	    // *options 禁止常量表达式作为测试条件  https://eslint.org/docs/rules/no-constant-condition
	    'no-constant-condition': ['error', { checkLoops: true }],
	    // 禁止在constructor中return一个值
	    'no-constructor-return': 'off',
	    // * 禁止在正则表达式中使用控制字符(ASCII:0~31)
	    'no-control-regex': 'error',
	    // * 禁止使用debugger
	    'no-debugger': 'error',
	    // * 禁止函数定义中出现重复的参数
	    'no-dupe-args': 'error',
	    // * 禁止class中定义重复的成员
	    'no-dupe-class-members': 'error',
	    // * 禁止else if中使用重复的条件
	    'no-dupe-else-if': 'error',
	    // * 禁止对象字面量中使用重复的key
	    'no-dupe-keys': 'error',
	    // * 禁止switch出现重复的case
	    'no-duplicate-case': 'error',
	    // options 禁止重复import模块  https://eslint.org/docs/rules/no-duplicate-imports
	    'no-duplicate-imports': ['off', { includeExports: false }],
	    // * 禁止在正则表达式中使用空字符集
	    'no-empty-character-class': 'error',
	    // * 禁止空的结构模式
	    'no-empty-pattern': 'error',
	    // * 禁止catch语句中修改exception参数
	    'no-ex-assign': 'error',
	    // *options 禁止case语句落空  https://eslint.org/docs/rules/no-fallthrough
	    'no-fallthrough': ['error', { commentPattern: 'falls?\\s?through' }],
	    // * 禁止对函数声明重新赋值
	    'no-func-assign': 'error',
	    // * 禁止直接赋值import导入的变量
	    'no-import-assign': 'error',
	    // *options 禁止在嵌套的块作用域中使用var或函数声明 https://eslint.org/docs/rules/no-inner-declarations
	    'no-inner-declarations': ['error', 'functions'],
	    // *options 禁止在 RegExp 构造函数中使用无效的正则表达式字符串  https://eslint.org/docs/rules/no-invalid-regexp
	    'no-invalid-regexp': ['error', { allowConstructorFlags: [] }],
	    // *options 禁止不规则的空白(可以配置字符串,模板字符串,注释,正则表达式字面量)  https://eslint.org/docs/rules/no-irregular-whitespace
	    'no-irregular-whitespace': ['error', { skipStrings: true }],
	    // * 禁止使用超出浮点数精度的数字字面量
	    'no-loss-of-precision': 'error',
	    // * 禁止正则表达式中使用多代码点组成的一个字符
	    'no-misleading-character-class': 'error',
	    // * 禁止Symbol构造函数(本来也不支持)
	    'no-new-symbol': 'error',
	    // * 禁止某些全局对象被当作函数或构造函数调用(Math,Date,Reflect,Atomics)
	    'no-obj-calls': 'error',
	    // 禁止从new Promise()的函数参数中return一个值
	    'no-promise-executor-return': 'off',
	    // * 禁止直接在对象实例上调用某些 Object.prototype 方法(call,apply可以)
	    'no-prototype-builtins': 'error',
	    // *options 禁止自身赋值  https://eslint.org/docs/rules/no-self-assign
	    'no-self-assign': ['error', { props: true }],
	    // 禁止自身比较
	    'no-self-compare': 'off',
	    // * 禁止setter函数return一个值
	    'no-setter-return': 'error',
	    // * 禁止稀疏数组
	    'no-sparse-arrays': 'error',
	    // 禁止在常规字符串中出现模板字面量占位符语法
	    'no-template-curly-in-string': 'off',
	    // * 禁止在派生类构造函数中在super()调用之前使用this/super
	    'no-this-before-super': 'error',
	    // *options 禁止使用未声明变量  https://eslint.org/docs/rules/no-undef
	    'no-undef': ['error', { typeof: false }],
	    // * 禁止令人困惑的多行表达式
	    'no-unexpected-multiline': 'error',
	    // 禁止一成不变的循环条件
	    'no-unmodified-loop-condition': 'off',
	    // * 禁止return, throw, break, continue之后出现的无法执行的语句及子类构造函数没有调用super()
	    'no-unreachable': 'error',
	    // options 禁止最多只有一次的循环  https://eslint.org/docs/rules/no-unreachable-loop
	    'no-unreachable-loop': ['off', { ignore: [] }],
	    // * 禁止finally块中直接使用return, throw, break, continue
	    'no-unsafe-finally': 'error',
	    // *options 禁止对关系运算符的左操作数使用否定操作符  https://eslint.org/docs/rules/no-unsafe-negation
	    'no-unsafe-negation': ['error', { enforceForOrderingRelations: false }],
	    // *options 禁止在不允许使用undefined的上下文中使用可选链(?.)  https://eslint.org/docs/rules/no-unsafe-options-chaining
	    'no-unsafe-optional-chaining': [
	      'error',
	      { disallowArithmeticOperators: false },
	    ],
	    // 禁止未使用的私有类成员对象
	    'no-unused-private-class-members': 'off',
	    // *options 禁止出现未使用的变量  https://eslint.org/docs/rules/no-unused-vars
	    'no-unused-vars': [
	      'error',
	      {
	        vars: 'all',
	        args: 'after-used',
	        caughtErrors: 'none',
	        ignoreRestSiblings: false,
	      },
	    ],
	    // options 禁止未声明就使用  https://eslint.org/docs/rules/no-use-before-define
	    'no-use-before-define': [
	      'off',
	      { classes: true, functions: true, variables: true },
	    ],
	    // * 禁止在正则表达式中使用无用的反向引用
	    'no-useless-backreference': 'error',
	    // options 禁止由于 await 或 yield的使用而可能导致出现竞态条件的赋值  https://eslint.org/docs/rules/require-atomic-updates
	    'require-atomic-updates': ['off', { allowProperties: false }],
	    // *options 使用isNaN()检查NaN  https://eslint.org/docs/rules/use-isnan
	    'use-isnan': [
	      'error',
	      { enforceForSwitchCase: true, enforceForIndexOf: false },
	    ],
	    // *options 强制typeof表达式与有效的字符串字面量比较  https://eslint.org/docs/rules/valid-typeof
	    'valid-typeof': ['error', { requireStringLiterals: true }],
	
	    /* Suggestions: These rules suggest alternate ways of doing things */
	    // options 强制getter和setter成对出现在Object和Class中(默认可以只有getter)  https://eslint.org/docs/rules/accessor-pairs
	    'accessor-pairs': [
	      'off',
	      {
	        setWithoutGet: true,
	        getWithoutSet: false,
	        enforceForClassMembers: true,
	      },
	    ],
	    // (options) 需要在箭头函数体中使用大括号(只有as-needed才可以使用第三个参数)
	    'arrow-body-style': [
	      'off',
	      'as-needed',
	      { requireReturnForObjectLiteral: false },
	    ],
	    // 模拟var像let一样拥有块作用域
	    'block-scoped-var': 'off',
	    // options 使用驼峰命名  https://eslint.org/docs/rules/camelcase
	    camelcase: [
	      'off',
	      {
	        properties: 'always',
	        ignoreDestructuring: false,
	        ignoreImports: false,
	        ignoreGlobals: false,
	        allow: [],
	      },
	    ],
	    // (options) 强制或禁止对注释的第一个字母大写(可以使用block,line单独配置单行多行注释)  https://eslint.org/docs/rules/capitalized-comments
	    'capitalized-comments': [
	      'off',
	      'always',
	      {
	        ignorePattern: 'jscs|jshint|eslint|istanbul|global|globals|exported',
	        ignoreInlineComments: false,
	        ignoreConsecutiveComments: false,
	      },
	    ],
	    // options 强制类中的方法使用this, 否则需要将不使用this的实例方法改为静态方法  https://eslint.org/docs/rules/class-methods-use-this
	    'class-methods-use-this': [
	      'off',
	      { enforceForClassFields: true, exceptMethods: [] },
	    ],
	    // options 限制程序中允许的最大环路复杂度(为了降低程序复杂度)  https://eslint.org/docs/rules/complexity
	    complexity: ['off', { max: 20 }],
	    // options 要求return语句要么总是返回值要么不返回  https://eslint.org/docs/rules/consistent-return
	    'consistent-return': ['off', { treatUndefinedAsUnspecified: false }],
	    // options 要求使用统一的this别名  https://eslint.org/docs/rules/consistent-this
	    'consistent-this': ['off', 'that'],
	    // (options) 单行语句是否使用花括号  https://eslint.org/docs/rules/curly
	    curly: ['off', 'multi'],
	    // options switch语句是否需要default  https://eslint.org/docs/rules/default-case
	    'default-case': ['off', { commentPattern: '^no\\sdefault' }],
	    // 强制default子句在switch语句的最后
	    'default-case-last': 'off',
	    // 强制默认值参数在函数参数列表的最后
	    'default-param-last': 'off',
	    // (options) 尽可能使用点符号  https://eslint.org/docs/rules/dot-notation
	    'dot-notation': ['off', { allowKeywords: true, allowPattern: '' }],
	    // (options) 尽可能使用===和!==(always可以配置第2个参数, smart不需要)  https://eslint.org/docs/rules/eqeqeq
	    eqeqeq: ['off', 'always', { null: 'always' }],
	    // options 需要函数名与赋值的变量名或属性名一致  https://eslint.org/docs/rules/func-name-matching
	    'func-name-matching': [
	      'off',
	      'always',
	      {
	        considerPropertyDescriptor: false,
	        includeCommonJSModuleExports: false,
	      },
	    ],
	    // options 要求或禁止带名称的函数表达式  https://eslint.org/docs/rules/func-names
	    'func-names': ['off', 'always', { generators: 'always' }],
	    // options 强制一致的使用函数声明或函数表达式形式(当第2个参数为declaration,第3个参数才会生效)  https://eslint.org/docs/rules/func-style
	    'func-style': ['off', 'expression', { allowArrowFunctions: false }],
	    // options 假如对象字面量或类中存在getter,setter函数, 强制getter和setter相邻  https://eslint.org/docs/rules/grouped-accessor-pairs
	    'grouped-accessor-pairs': ['off', 'anyOrder'],
	    // 需要过滤for-in循环可能继承自原型链的属性(Object.prototype.hasOwnProperty)
	    'guard-for-in': 'off',
	    // options 禁止使用指定的标识符作为变量名, 函数名, 对象属性, 类成员对象(第1个参数之后全部是禁用的标识符)  https://eslint.org/docs/rules/id-denylist
	    'id-denylist': ['off'],
	    // options 强制标识符的最小和最大长度  https://eslint.org/docs/rules/id-length
	    'id-length': [
	      'off',
	      {
	        min: 2,
	        max: Infinity,
	        properties: 'always',
	        exceptions: [],
	        exceptionPatterns: [],
	      },
	    ],
	    // options 需要标识符满足特定的正则表达式(第2个参数是正则表达式字符串)  https://eslint.org/docs/rules/id-match
	    'id-match': [
	      'off',
	      '',
	      {
	        properties: false,
	        classFields: false,
	        onlyDeclarations: false,
	        ignoreDestructuring: false,
	      },
	    ],
	    // options 需要或禁止在变量声明时初始化(第2个参数为never时, 第3个参数生效)  https://eslint.org/docs/rules/init-declarations
	    'init-declarations': ['off', 'always', { ignoreForLoopInit: true }],
	    // options 限制每个文件class的最大数量  https://eslint.org/docs/rules/max-classes-per-file
	    'max-classes-per-file': ['off', { max: 1, ignoreExpressions: false }],
	    // options 限制循环嵌套的最大深度  https://eslint.org/docs/rules/max-depth
	    'max-depth': ['off', { max: 4 }],
	    // options 限制每个文件的最大行数  https://eslint.org/docs/rules/max-lines
	    'max-lines': [
	      'off',
	      { max: 300, skipBlankLines: false, skipComments: false },
	    ],
	    // options 限制每个函数的最大行数  https://eslint.org/docs/rules/max-lines-per-function
	    'max-lines-per-function': [
	      'off',
	      { max: 50, skipBlankLines: false, skipComments: false, IIFEs: false },
	    ],
	    // options 限制可以嵌套的最大深度的回调函数  https://eslint.org/docs/rules/max-nested-callbacks
	    'max-nested-callbacks': ['off', { max: 10 }],
	    // options 限制函数定义的参数的最大数量  https://eslint.org/docs/rules/max-params
	    'max-params': ['off', { max: 3 }],
	    // options 限制函数体中语句的最大数量  https://eslint.org/docs/rules/max-statements
	    'max-statements': ['off', { max: 10 }, { ignoreTopLevelFunctions: false }],
	    // (options) 强制多行注释采用特定的格式  https://eslint.org/docs/rules/multiline-comment-style
	    'multiline-comment-style': ['off', 'starred-block'],
	    // options 要求构造函数名的首字母大写  https://eslint.org/docs/rules/new-cap
	    'new-cap': [
	      'off',
	      {
	        newIsCap: true,
	        capIsNew: true,
	        properties: true,
	        newIsCapExceptions: [],
	        newIsCapExceptionPattern: '',
	        capIsNewExceptions: [],
	        capIsNewExceptionPattern: '',
	      },
	    ],
	    // 禁止alert弹出框类型的函数
	    'no-alert': 'off',
	    // 禁止使用Array构造函数
	    'no-array-constructor': 'off',
	    // options 禁止按位运算符  https://eslint.org/docs/rules/no-bitwise
	    'no-bitwise': ['off', { allow: [], int32Hint: false }],
	    // 禁止使用caller或callee(arguments.caller/arguments.callee)
	    'no-caller': 'off',
	    // * 禁止在case/default子句中使用词法声明(let,const,function and class)
	    'no-case-declarations': 'error',
	    // (options) 禁止在可能与比较运算符混淆的地方使用箭头函数  https://eslint.org/docs/rules/no-confusing-arrow
	    'no-confusing-arrow': ['off', { allowParens: true }],
	    // options 禁止使用console对象  https://eslint.org/docs/rules/no-console
	    'no-console': ['off', { allow: [] }],
	    // 禁用continue语句
	    'no-continue': 'off',
	    // * 禁止使用delete删除变量
	    'no-delete-var': 'error',
	    // () 禁止除法操作符显式的出现在正则表达式开始的位置
	    'no-div-regex': 'off',
	    // (options) 禁止if和else块中都return  https://eslint.org/docs/rules/no-else-return
	    'no-else-return': ['off', { allowElseIf: true }],
	    // *options 禁止出现空语句块  https://eslint.org/docs/rules/no-empty
	    'no-empty': ['error', { allowEmptyCatch: false }],
	    // options 禁止出现空函数  https://eslint.org/docs/rules/no-empty-function
	    'no-empty-function': ['off', { allow: [] }],
	    // 禁止在没有类型检查操作符(==或!=)的情况下与 null 进行比较
	    'no-eq-null': 'off',
	    // options 禁止eval()  https://eslint.org/docs/rules/no-eval
	    'no-eval': ['off', { allowIndirect: false }],
	    // options 禁止直接扩展内置的原生的对象  https://eslint.org/docs/rules/no-extend-native
	    'no-extend-native': ['off', { exceptions: [] }],
	    // () 禁止非必要的函数绑定bind()
	    'no-extra-bind': 'off',
	    // (*options) 禁止非必要的布尔转换  https://eslint.org/docs/rules/no-extra-boolean-cast
	    'no-extra-boolean-cast': ['error', { enforceForLogicalOperands: false }],
	    // () 禁止非必要的标签
	    'no-extra-label': 'off',
	    // (*) 禁止非必要的分号
	    'no-extra-semi': 'error',
	    // () 禁止小数点前后数字的缺失
	    'no-floating-decimal': 'off',
	    // *options 禁止修改内置原生对象或只读的全局变量  https://eslint.org/docs/rules/no-global-assign
	    'no-global-assign': ['error', { exceptions: [] }],
	    // (options) 禁止使用类型转换较短的符号模式,使用基本类型包装器  https://eslint.org/docs/rules/no-implicit-coercion
	    'no-implicit-coercion': [
	      'off',
	      {
	        boolean: true,
	        number: true,
	        string: true,
	        disallowTemplateShorthand: false,
	        allow: [],
	      },
	    ],
	    // options 禁止在全局作用域中声明  https://eslint.org/docs/rules/no-implicit-globals
	    'no-implicit-globals': ['off', { lexicalBindings: false }],
	    // 禁止使用隐式eval(), setTimeout,setInterval第一个参数可以是字符串, 会被当做函数体执行
	    'no-implied-eval': 'off',
	    // options 禁止代码与注释在同一行  https://eslint.org/docs/rules/no-inline-comments
	    'no-inline-comments': ['off', { ignorePattern: '' }],
	    // options 限制类或类对象之外的this的使用  https://eslint.org/docs/rules/no-invalid-this
	    'no-invalid-this': ['off', { capIsConstructor: true }],
	    // 禁止使用__iterator__属性
	    'no-iterator': 'off',
	    // 禁止标签和变量拥有同样的名称
	    'no-label-var': 'off',
	    // options 禁止使用带标签的语句  https://eslint.org/docs/rules/no-labels
	    'no-labels': ['off', { allowLoop: false, allowSwitch: false }],
	    // 禁止不必要的嵌套块
	    'no-lone-blocks': 'off',
	    // () 禁止if子句作为else子句的唯一语句(应该使用else if)
	    'no-lonely-if': 'off',
	    // 禁止在循环语句中出现包含不安全引用的函数声明
	    'no-loop-func': 'off',
	    // options 禁止使用含义不明的数字(比如60可以代表分也可以代表秒)  https://eslint.org/docs/rules/no-magic-numbers
	    'no-magic-numbers': [
	      'off',
	      {
	        ignore: [],
	        ignoreArrayIndexes: false,
	        ignoreDefaultValues: false,
	        enforceConst: false,
	        detectObjects: false,
	      },
	    ],
	    // options 禁止混用不同的操作符(尽量用括号包裹一下)  https://eslint.org/docs/rules/no-mixed-operators
	    'no-mixed-operators': ['off', { groups: [[]], allowSamePrecedence: true }],
	    // options 禁止链式赋值表达式  https://eslint.org/docs/rules/no-multi-assign
	    'no-multi-assign': ['off', { ignoreNonDeclaration: false }],
	    // 禁止使用\把单行字符串写成多行
	    'no-multi-str': 'off',
	    // 禁止在后面有else分支的if条件或三元表达式中使用否定条件
	    'no-negated-condition': 'off',
	    // 禁用new调用构造函数但不赋值给变量的操作
	    'no-new': 'off',
	    // 禁止直接使用Function构造函数
	    'no-new-func': 'off',
	    // 禁止直接使用Object构造函数
	    'no-new-object': 'off',
	    // 禁止new和基础包装类一起使用
	    'no-new-wrappers': 'off',
	    // * 禁止字符串字面量中使用\8,\9转义序列
	    'no-nonoctal-decimal-escape': 'error',
	    // * 禁止使用八进制字面量
	    'no-octal': 'error',
	    // 禁止字符串字面量中使用八进制转义序列
	    'no-octal-escape': 'off',
	    // options 禁止修改函数参数(当props为true时, 两个数组中值代表对象的属性可以修改)  https://eslint.org/docs/rules/no-param-reassign
	    'no-param-reassign': [
	      'off',
	      {
	        props: false,
	        ignorePropertyModificationsFor: [],
	        ignorePropertyModificationsForRegex: [],
	      },
	    ],
	    // options 禁止使用一元操作符++和--  https://eslint.org/docs/rules/no-plusplus
	    'no-plusplus': ['off', { allowForLoopAfterthoughts: false }],
	    // 禁止使用__proto__属性(Object,getPrototypeOf, Object.setPrototypeOf)
	    'no-proto': 'off',
	    // options 禁止在同一上下文中变量声明多次
	    'no-redeclare': ['off', { builtinGlobals: true }],
	    // (*) 禁止正则表达式字面量中出现多个连续空格
	    'no-regex-spaces': 'error',
	    // options 禁止使用export导出特定的名称(对export default无效)  https://eslint.org/docs/rules/no-restricted-exports
	    'no-restricted-exports': ['off', { restrictedNamedExports: [] }],
	    // options 禁用特定的全局变量  https://eslint.org/docs/rules/no-restricted-globals
	    'no-restricted-globals': ['off', ''],
	    // options 禁止使用import或require导入特定的名称  https://eslint.org/docs/rules/no-restricted-imports
	    'no-restricted-imports': ['off', { paths: [], patterns: [] }],
	    // options 禁止使用某个对象的某个属性 https://eslint.org/docs/rules/no-restricted-properties
	    'no-restricted-properties': [
	      'off',
	      { object: '', property: '', message: '' },
	    ],
	    // options 禁止使用特定的语法  https://eslint.org/docs/rules/no-restricted-syntax
	    'no-restricted-syntax': ['off', { selector: '', message: '' }],
	    // options 禁止在return语句中赋值  https://eslint.org/docs/rules/no-return-assign
	    'no-return-assign': ['off', 'except-parens'],
	    // 禁用不必要的return await
	    'no-return-await': 'off',
	    // 禁止javascript: URL
	    'no-script-url': 'off',
	    // options 禁止使用逗号操作符  https://eslint.org/docs/rules/no-sequences
	    'no-sequences': ['off', { allowInParentheses: true }],
	    // options 禁止当前作用域声明的变量与父级作用域声明的变量名一致  https://eslint.org/docs/rules/no-shadow
	    'no-shadow': [
	      'off',
	      { builtinGlobals: false, hoist: 'functions', allow: [] },
	    ],
	    // * 禁止将标识符定义为受限的名称
	    'no-shadow-restricted-names': 'error',
	    // 禁止使用三元表达式
	    'no-ternary': 'off',
	    // 禁止throw基础类型字面量
	    'no-throw-literal': 'off',
	    // () 禁止使用undefined作为初始化值
	    'no-undef-init': 'off',
	    // 禁止使用undefined变量
	    'no-undefined': 'off',
	    // options 禁止在标识符前后使用_  https://eslint.org/docs/rules/no-underscore-dangle
	    'no-underscore-dangle': [
	      'off',
	      {
	        allow: [],
	        allowAfterThis: false,
	        allowAfterSuper: false,
	        allowAfterThisConstructor: false,
	        allowFunctionParams: true,
	        enforceInMethodNames: false,
	      },
	    ],
	    // (options) 禁止不必要的三元表达式  https://eslint.org/docs/rules/no-unneeded-ternary
	    'no-unneeded-ternary': ['off', { defaultAssignment: true }],
	    // options 禁止对程序状态没有影响的无用表达式(比如 n+1 而不是 n += 1)  https://eslint.org/docs/rules/no-unused-expressions
	    'no-unused-expressions': [
	      'off',
	      {
	        allowShortCircuit: false,
	        allowTernary: false,
	        allowTaggedTemplates: false,
	        enforceForJSX: false,
	      },
	    ],
	    // (*) 禁止出现未使用的标签
	    'no-unused-labels': 'error',
	    // 禁止非必要的call,apply调用
	    'no-useless-call': 'off',
	    // * 禁止不必要的catch子句
	    'no-useless-catch': 'error',
	    // (options) 禁止对象或类中使用不必要的计算属性key(动态键)  https://eslint.org/docs/rules/no-useless-computed-key
	    'no-useless-computed-key': ['off', { enforceForClassMembers: false }],
	    // 禁止不必要的字符串拼接
	    'no-useless-concat': 'off',
	    // 禁止出现不必要的构造函数(和隐藏构造函数一致就可以删除)
	    'no-useless-constructor': 'off',
	    // * 禁止不必要的转义字符
	    'no-useless-escape': 'error',
	    // (options) 禁止import, export, 和结构赋值中原名称与重命名一致  https://eslint.org/docs/rules/no-useless-rename
	    'no-useless-rename': [
	      'off',
	      { ignoreImport: false, ignoreExport: false, ignoreDestructuring: false },
	    ],
	    // () 禁止多余的return;
	    'no-useless-return': 'off',
	    // () 建议使用let和const, 禁止使用var
	    'no-var': 'off',
	    // options 禁止使用void操作符  https://eslint.org/docs/rules/no-void
	    'no-void': ['off', { allowAsStatement: false }],
	    // options 禁止警告注释  https://eslint.org/docs/rules/no-warning-comments
	    'no-warning-comments': [
	      'off',
	      { terms: ['todo', 'fixme', 'xxx'], location: 'start' },
	    ],
	    // * 禁止使用with语句
	    'no-with': 'error',
	    // (options) 需要对象字面量的简写语法(省略冒号:)  https://eslint.org/docs/rules/object-shorthand
	    'object-shorthand': ['off', 'always'],
	    // (options) 强制函数中的变量要么一起声明要么单独声明  https://eslint.org/docs/rules/one-var
	    'one-var': ['off', 'always'],
	    // (options) 要求或强制在变量声明周围换行(每行只有一个变量)  https://eslint.org/docs/rules/one-var-declaration-per-line
	    'one-var-declaration-per-line': ['off', 'initializations'],
	    // (options) 要求或禁止在可以使用赋值操作符缩写的时候使用  https://eslint.org/docs/rules/operator-assignment
	    'operator-assignment': ['off', 'always'],
	    // (options) 要求回调函数或函数表达式使用箭头函数  https://eslint.org/docs/rules/prefer-arrow-callback
	    'prefer-arrow-callback': [
	      'off',
	      { allowNamedFunctions: false, allowUnboundThis: true },
	    ],
	    // (options) 如果可以, 建议优先使用const  https://eslint.org/docs/rules/prefer-const
	    'prefer-const': [
	      'off',
	      { destructuring: 'any', ignoreReadBeforeAssign: false },
	    ],
	    // (options) 如果可以, 建议对数组或对象使用解构  https://eslint.org/docs/rules/prefer-destructuring
	    'prefer-destructuring': [
	      'off',
	      {
	        VariableDeclarator: { object: true, array: true },
	        AssignmentExpression: { object: true, array: true },
	      },
	      {
	        enforceForRenamedProperties: false,
	      },
	    ],
	    // () 禁用Math.pow, 要求使用 **
	    'prefer-exponentiation-operator': 'off',
	    // 建议在正则表达式中使用命名捕获组
	    'prefer-named-capture-group': 'off',
	    // () 建议直接使用二进制,八进制,十六进制数字字面量
	    'prefer-numeric-literals': 'off',
	    // () 建议使用对象扩展运算符而不是Object.assign
	    'prefer-object-spread': 'off',
	    // options 要求使用内置Error对象的实例作为Promise reject的参数  https://eslint.org/docs/rules/prefer-promise-reject-errors
	    'prefer-promise-reject-errors': ['off', { allowEmptyReject: false }],
	    // options 建议使用正则表达式字面量而不是正则表达式构造函数  https://eslint.org/docs/rules/prefer-regex-literals
	    'prefer-regex-literals': ['off', { disallowRedundantWrapping: false }],
	    // 建议使用剩余参数而不是arguments
	    'prefer-rest-params': 'off',
	    // 建议可变参数函数使用扩展语法而不是apply
	    'prefer-spread': 'off',
	    // () 建议使用模板字符串而不是字符串拼接
	    'prefer-template': 'off',
	    // (options) 对象字面量的属性名需要引号包裹  https://eslint.org/docs/rules/quote-props
	    'quote-props': [
	      'off',
	      'always',
	      { keywords: true, unnecessary: true, numbers: true },
	    ],
	    // options 需要在parseInt中使用基数参数  https://eslint.org/docs/rules/radix
	    radix: ['off', 'always'],
	    // 禁止不带await表达式的async函数
	    'require-await': 'off',
	    // 强制正则表达式中使用u标志
	    'require-unicode-regexp': 'off',
	    // * 禁止生成器函数中没有使用yield关键字
	    'require-yield': 'error',
	    // (options) 检查导入声明并按照首字母及别名排序  https://eslint.org/docs/rules/sort-imports
	    'sort-imports': [
	      'off',
	      {
	        ignoreCase: false,
	        ignoreDeclarationSort: false,
	        ignoreMemberSort: false,
	        memberSyntaxSortOrder: ['none', 'all', 'multiple', 'single'],
	        allowSeparatedGroups: false,
	      },
	    ],
	    // options 要求对象的属性按照字母顺序排序  https://eslint.org/docs/rules/sort-keys
	    'sort-keys': [
	      'off',
	      'asc',
	      { caseSensitive: true, minKeys: 2, natural: false },
	    ],
	    // (options) 要求同一个声明块中的变量按字母顺序排列  https://eslint.org/docs/rules/sort-vars
	    'sort-vars': ['off', { ignoreCase: false }],
	    // (options) 需要或禁止注释起点后的空格  https://eslint.org/docs/rules/spaced-comment
	    'spaced-comment': ['off', 'always', { exceptions: [], markers: [] }],
	    // (options) 需要或者禁止strict指令  https://eslint.org/docs/rules/strict
	    strict: ['off', 'safe'],
	    // 要求Symbol函数有一个描述参数
	    'symbol-description': 'off',
	    // 将当前作用域的变量提升到顶部
	    'vars-on-top': 'off',
	    // (options) 要求或禁止Yoda条件(字面量的值放在变量前)  https://eslint.org/docs/rules/yoda
	    yoda: ['off', 'never', { exceptRange: false, onlyEquality: false }],
	
	    /* Layout & Formatting: These rules care about how the code looks rather than how it executes */
	    // (options) 强制数组左括号之后右括号之前换行  https://eslint.org/docs/rules/array-bracket-newline
	    'array-bracket-newline': [
	      'off',
	      'consistent',
	      { multiline: true, minItems: null },
	    ],
	    // (options) 强制或禁止数组及解构赋值左右的空格  https://eslint.org/docs/rules/array-bracket-spacing
	    'array-bracket-spacing': [
	      'off',
	      'never',
	      { singleValue: true, objectsInArrays: true, arraysInArrays: true },
	    ],
	    // (options) 强制数组元素之间换行  https://eslint.org/docs/rules/array-element-newline
	    'array-element-newline': ['off', 'always'],
	    // (options) 箭头函数参数需要用括号包裹  https://eslint.org/docs/rules/arrow-parens
	    'arrow-parens': ['off', 'always'],
	    // (options) 箭头函数箭头的前后需要空格  https://eslint.org/docs/rules/arrow-spacing
	    'arrow-spacing': ['off', { before: true, after: true }],
	    // (options) 禁止或强制块作用域括号与内容之间有空格  https://eslint.org/docs/rules/block-spacing
	    'block-spacing': ['off', 'always'],
	    // (options) 强制在代码块中使用一致的大括号风格  https://eslint.org/docs/rules/brace-style
	    'brace-style': ['off', '1tbs', { allowSingleLine: false }],
	    // (options) 需要或者禁用数组或对象的尾部逗号  https://eslint.org/docs/rules/comma-dangle
	    'comma-dangle': ['off', 'never'],
	    // (options) 强制逗号前后的空格样式  https://eslint.org/docs/rules/comma-spacing
	    'comma-spacing': ['off', { before: false, after: true }],
	    // (options) 强制使用一致的逗号风格  https://eslint.org/docs/rules/comma-style
	    'comma-style': ['off', 'last'],
	    // (options) 禁止或强制计算属性(动态属性)内部的空格样式  https://eslint.org/docs/rules/computed-property-spacing
	    'computed-property-spacing': ['off', 'never'],
	    // (options) 强制点号前后的换行风格(与对象一行还是与属性一行)  https://eslint.org/docs/rules/dot-location
	    'dot-location': ['off', 'object'],
	    // (options) 需要或禁止文件最后添加换行  https://eslint.org/docs/rules/eol-last
	    'eol-last': ['off', 'always'],
	    // (options) 要求或禁止在函数名称和调用它的左括号之间使用空格  https://eslint.org/docs/rules/func-call-spacing
	    'func-call-spacing': ['off', 'never'],
	    // (options) 强制函数调用的参数之间换行  https://eslint.org/docs/rules/function-call-argument-newline
	    'function-call-argument-newline': ['off', 'always'],
	    // (options) 在函数参数或参数的括号内强制执行一致的换行符  https://eslint.org/docs/rules/function-paren-newline
	    'function-paren-newline': ['off', 'multiline'],
	    // (options) 强制生成器函数符号*左右的空格  https://eslint.org/docs/rules/generator-star-spacing
	    'generator-star-spacing': ['off', { before: true, after: false }],
	    // (options) 强制维持隐式返回的箭头函数方法体的位置的一致性  https://eslint.org/docs/rules/implicit-arrow-linebreak
	    'implicit-arrow-linebreak': ['off', 'beside'],
	    // (options) 强制维持代码缩进的一致性  https://eslint.org/docs/rules/indent
	    indent: ['off', 4],
	    // (options) 强制在 JSX 属性中一致使用双引号或单引号  https://eslint.org/docs/rules/jsx-quotes
	    'jsx-quotes': ['off', 'prefer-double'],
	    // (options) 强制对象字面量属性中的键和值之间保持一致的间距  https://eslint.org/docs/rules/key-spacing
	    'key-spacing': [
	      'off',
	      { beforeColon: false, afterColon: true, mode: 'strict' },
	    ],
	    // (options) 强制关键字周围保持一致的间距  https://eslint.org/docs/rules/keyword-spacing
	    'keyword-spacing': ['off', { before: true, after: true }],
	    // options 强制单行注释的位置  https://eslint.org/docs/rules/line-comment-position
	    'line-comment-position': ['off', { position: 'above' }],
	    // (options) 强制执行一致的行尾样式  https://eslint.org/docs/rules/linebreak-style
	    'linebreak-style': ['off', 'unix'],
	    // (options) 要求注释前后空行  https://eslint.org/docs/rules/lines-around-comment
	    'lines-around-comment': ['off', { beforeBlockComment: true }],
	    // (options) 要求或禁止类成员之间空行  https://eslint.org/docs/rules/lines-between-class-members
	    'lines-between-class-members': ['off', 'always'],
	    // options 强制单行的最大字符数  https://eslint.org/docs/rules/max-len
	    'max-len': ['off', { code: 80, tabWidth: 4 }],
	    // options 强制每行允许的最大语句数  https://eslint.org/docs/rules/max-statements-per-line
	    'max-statements-per-line': ['off', { max: 1 }],
	    // (options) 强制或禁止三元表达式的操作数之间换行  https://eslint.org/docs/rules/multiline-ternary
	    'multiline-ternary': ['off', 'always'],
	    // (options) 强制或禁止new关键字调用无参构造函数的时候省略括号  https://eslint.org/docs/rules/new-parens
	    'new-parens': ['off', 'always'],
	    // (options) 每链式调用一个方法后需要换行  https://eslint.org/docs/rules/newline-per-chained-call
	    'newline-per-chained-call': ['off', { ignoreChainWithDepth: 2 }],
	    // (options) 禁止不必要的括号  https://eslint.org/docs/rules/no-extra-parens
	    'no-extra-parens': ['off', 'all'],
	    // *options 禁止混用tab和空格用于缩进  https://eslint.org/docs/rules/no-mixed-spaces-and-tabs
	    'no-mixed-spaces-and-tabs': ['error'],
	    // (options) 禁止不是用于缩进的多个空格  https://eslint.org/docs/rules/no-multi-spaces
	    'no-multi-spaces': [
	      'off',
	      { ignoreEOLComments: false, exceptions: { Property: true } },
	    ],
	    // (options) 禁止多个连续的换行  https://eslint.org/docs/rules/no-multiple-empty-lines
	    'no-multiple-empty-lines': ['off', { max: 2 }],
	    // options 禁止tab字符  https://eslint.org/docs/rules/no-tabs
	    'no-tabs': ['off', { allowIndentationTabs: false }],
	    // (options) 禁止行尾出现尾随空白字符  https://eslint.org/docs/rules/no-trailing-spaces
	    'no-trailing-spaces': [
	      'off',
	      { skipBlankLines: false, ignoreComments: false },
	    ],
	    // () 如果链式调用的属性在同一行则.号前不允许有空白
	    'no-whitespace-before-property': 'off',
	    // (options) 强制单行语句执行一致的位置  https://eslint.org/docs/rules/nonblock-statement-body-position
	    'nonblock-statement-body-position': ['off', 'beside'],
	    // (options) 强制大括号内换行符的一致性  https://eslint.org/docs/rules/object-curly-newline
	    'object-curly-newline': ['off', { consistent: true }],
	    // (options) 强制在大括号中使用一致的空格  https://eslint.org/docs/rules/object-curly-spacing
	    'object-curly-spacing': ['off', 'never'],
	    // (options) 强制将对象的属性放在不同的行上  https://eslint.org/docs/rules/object-property-newline
	    'object-property-newline': ['off', { allowAllPropertiesOnSameLine: false }],
	    // (options) 强制运算符执行一致的换行样式  https://eslint.org/docs/rules/operator-linebreak
	    'operator-linebreak': [
	      'off',
	      'after',
	      { overrides: { '?': 'before', ':': 'before' } },
	    ],
	    // (options) 要求或禁止块内执行一致的空行填充  https://eslint.org/docs/rules/padded-blocks
	    'padded-blocks': ['off', 'always', { allowSingleLineBlocks: false }],
	    // (options) 要求或禁止语句间空行填充  https://eslint.org/docs/rules/padding-line-between-statements
	    'padding-line-between-statements': ['off'],
	    // (options) 强制一致使用反引号、双引号或单引号  https://eslint.org/docs/rules/quotes
	    quotes: ['off', 'double'],
	    // (options) 强制剩余(rest)和扩展(spread)运算符及其表达式之间保持一致的间距  https://eslint.org/docs/rules/rest-spread-spacing
	    'rest-spread-spacing': ['off', 'never'],
	    // (options) 要求或禁止分号的使用,而不是自动插入分号  https://eslint.org/docs/rules/semi
	    semi: ['off', 'always', { omitLastInOneLineBlock: true }],
	    // (options) 强制分号前后的空格样式  https://eslint.org/docs/rules/semi-spacing
	    'semi-spacing': ['off', { before: false, after: true }],
	    // (options) 强制分号附近换行符的位置  https://eslint.org/docs/rules/semi-style
	    'semi-style': ['off', 'last'],
	    // (options) 需要或禁止块之前的空格  https://eslint.org/docs/rules/space-before-blocks
	    'space-before-blocks': ['off', 'always'],
	    // (options) 需要或禁止函数名与括号之间的空格  https://eslint.org/docs/rules/space-before-function-paren
	    'space-before-function-paren': ['off', 'always'],
	    // (options) 禁止或强制括号内部的空格样式  https://eslint.org/docs/rules/space-in-parens
	    'space-in-parens': ['off', 'never'],
	    // (options) 需要中缀运算符周围有空格  https://eslint.org/docs/rules/space-infix-ops
	    'space-infix-ops': ['off', { int32Hint: false }],
	    // (options) 要求或禁止在一元运算符之前/之后使用空格  https://eslint.org/docs/rules/space-unary-ops
	    'space-unary-ops': ['off', { words: true, nonwords: false, overrides: {} }],
	    // (options) 强制switch语句中case,default子句冒号周围的空格样式  https://eslint.org/docs/rules/switch-colon-spacing
	    'switch-colon-spacing': ['off', { before: false, after: true }],
	    // (options) 强制模板字符串变量内部的间距  https://eslint.org/docs/rules/template-curly-spacing
	    'template-curly-spacing': ['off', 'never'],
	    // (options) 要求或禁止模板标签函数和模板字面量之间的间距  https://eslint.org/docs/rules/template-tag-spacing
	    'template-tag-spacing': ['off', 'never'],
	    // (options) 需要或禁止Unicode字节顺序标记  https://eslint.org/docs/rules/unicode-bom
	    'unicode-bom': ['off', 'never'],
	    // (options) 需要用括号包裹立即调用函数表达式  https://eslint.org/docs/rules/wrap-iife
	    'wrap-iife': ['off', 'outside', { functionPrototypeMethods: false }],
	    // () 需要用括号包裹正则表达式字面量
	    'wrap-regex': 'off',
	    // (options) 强制yield*表达式中*周围的空格  https://eslint.org/docs/rules/yield-star-spacing
	    'yield-star-spacing': ['off', { before: false, after: true }],
	}
}

eslint 推荐配置

大部分还是使用recommended打勾的规则,其中layout和formatting部分的规则可以使用prettier来进行代码格式化,所以可以不用。

module.exports = {
	extends: ['eslint:recommended'],
  	parserOptions: {
		ecmaVersion: 'latest',
    	sourceType: 'module',
	},
	rules: {
		'no-debugger': 'error',
	    'default-param-last': 'error',
	    eqeqeq: ['warn', 'smart'],
	    'prefer-const': ['warn', { destructuring: 'all' }],
	    'no-empty': ['warn', { allowEmptyCatch: true }],
	    'no-unused-expressions': 'warn',
	    'require-await': 'warn',
	    'no-useless-escape': 'warn',
	    'no-warning-comments': [
	      'warn',
	      { terms: ['todo', 'fixme', 'xxx'], location: 'start' },
	    ],
	}
}

这样的配置对于有特殊文件的比如vue,ts,jsx,tsx就不太适合了,还需要添加另外的插件及规则。

标签:内置,off,no,rules,eslint,https,规则,options
来源: https://blog.csdn.net/qq_35134066/article/details/122018376

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有