Rules

Rules in ESLint are grouped by category to help you understand their purpose.

为了让你对规则有个更好的理解,ESLint 对其进行了分门别类。

No rules are enabled by default. The "extends": "eslint:recommended" property in a configuration file enables rules that report common problems, which have a check mark below.

所有的规则默认都是禁用的。在配置文件中,使用 "extends": "eslint:recommended" 来启用推荐的规则,报告一些常见的问题,在下文中这些推荐的规则都带有一个标记。

The --fix option on the command line automatically fixes problems (currently mostly whitespace) reported by rules which have a wrench below.

命令行--fix 选项用来自动修复规则所报告的问题(目前,大部分是对空白的修复),在下文中会有一个的图标。

Possible Errors

These rules relate to possible syntax or logic errors in JavaScript code:

这些规则与 JavaScript 代码中可能的错误或逻辑错误有关:

for-direction

enforce “for” loop update clause moving the counter in the right direction.

for-direction

强制 “for” 循环中更新子句的计数器朝着正确的方向移动

getter-return

enforce return statements in getters

getter-return

强制 getter 函数中出现 return 语句

no-async-promise-executor

disallow using an async function as a Promise executor

no-async-promise-executor

禁止使用异步函数作为 Promise executor

no-await-in-loop

disallow await inside of loops

no-await-in-loop

禁止在循环中出现 await

no-compare-neg-zero

disallow comparing against -0

no-compare-neg-zero

禁止与 -0 进行比较

no-cond-assign

disallow assignment operators in conditional expressions

no-cond-assign

禁止条件表达式中出现赋值操作符

no-console

disallow the use of console

no-console

禁用 console

no-constant-condition

disallow constant expressions in conditions

no-constant-condition

禁止在条件中使用常量表达式

no-control-regex

disallow control characters in regular expressions

no-control-regex

禁止在正则表达式中使用控制字符

no-debugger

disallow the use of debugger

no-debugger

禁用 debugger

no-dupe-args

disallow duplicate arguments in function definitions

no-dupe-args

禁止 function 定义中出现重名参数

no-dupe-keys

disallow duplicate keys in object literals

no-dupe-keys

禁止对象字面量中出现重复的 key

no-duplicate-case

disallow duplicate case labels

no-duplicate-case

禁止出现重复的 case 标签

no-empty

disallow empty block statements

no-empty

禁止出现空语句块

no-empty-character-class

disallow empty character classes in regular expressions

no-empty-character-class

禁止在正则表达式中使用空字符集

no-ex-assign

disallow reassigning exceptions in catch clauses

no-ex-assign

禁止对 catch 子句的参数重新赋值

no-extra-boolean-cast

disallow unnecessary boolean casts

no-extra-boolean-cast

禁止不必要的布尔转换

no-extra-parens

disallow unnecessary parentheses

no-extra-parens

禁止不必要的括号

no-extra-semi

disallow unnecessary semicolons

no-extra-semi

禁止不必要的分号

no-func-assign

disallow reassigning function declarations

no-func-assign

禁止对 function 声明重新赋值

no-inner-declarations

disallow variable or function declarations in nested blocks

no-inner-declarations

禁止在嵌套的块中出现变量声明或 function 声明

no-invalid-regexp

disallow invalid regular expression strings in RegExp constructors

no-invalid-regexp

禁止 RegExp 构造函数中存在无效的正则表达式字符串

no-irregular-whitespace

disallow irregular whitespace

no-irregular-whitespace

禁止不规则的空白

no-misleading-character-class

disallow characters which are made with multiple code points in character class syntax

no-misleading-character-class

不允许在字符类语法中出现由多个代码点组成的字符

no-obj-calls

disallow calling global object properties as functions

no-obj-calls

禁止把全局对象作为函数调用

no-prototype-builtins

disallow calling some Object.prototype methods directly on objects

no-prototype-builtins

禁止直接调用 Object.prototypes 的内置属性

no-regex-spaces

disallow multiple spaces in regular expressions

no-regex-spaces

禁止正则表达式字面量中出现多个空格

no-sparse-arrays

disallow sparse arrays

no-sparse-arrays

禁用稀疏数组

no-template-curly-in-string

disallow template literal placeholder syntax in regular strings

no-template-curly-in-string

禁止在常规字符串中出现模板字面量占位符语法

no-unexpected-multiline

disallow confusing multiline expressions

no-unexpected-multiline

禁止出现令人困惑的多行表达式

no-unreachable

disallow unreachable code after return, throw, continue, and break statements

no-unreachable

禁止在 returnthrowcontinuebreak 语句之后出现不可达代码

no-unsafe-finally

disallow control flow statements in finally blocks

no-unsafe-finally

禁止在 finally 语句块中出现控制流语句

no-unsafe-negation

disallow negating the left operand of relational operators

no-unsafe-negation

禁止对关系运算符的左操作数使用否定操作符

require-atomic-updates

disallow assignments that can lead to race conditions due to usage of await or yield

require-atomic-updates

禁止由于 awaityield的使用而可能导致出现竞态条件的赋值

use-isnan

require calls to isNaN() when checking for NaN

use-isnan

要求使用 isNaN() 检查 NaN

valid-typeof

enforce comparing typeof expressions against valid strings

valid-typeof

强制 typeof 表达式与有效的字符串进行比较

Best Practices

These rules relate to better ways of doing things to help you avoid problems:

这些规则是关于最佳实践的,帮助你避免一些问题

accessor-pairs

enforce getter and setter pairs in objects

accessor-pairs

强制 getter 和 setter 在对象中成对出现

array-callback-return

enforce return statements in callbacks of array methods

array-callback-return

强制数组方法的回调函数中有 return 语句

block-scoped-var

enforce the use of variables within the scope they are defined

block-scoped-var

强制把变量的使用限制在其定义的作用域范围内

class-methods-use-this

enforce that class methods utilize this

class-methods-use-this

强制类方法使用 this

complexity

enforce a maximum cyclomatic complexity allowed in a program

complexity

指定程序中允许的最大环路复杂度

consistent-return

require return statements to either always or never specify values

consistent-return

要求 return 语句要么总是指定返回的值,要么不指定

curly

enforce consistent brace style for all control statements

curly

强制所有控制语句使用一致的括号风格

default-case

require default cases in switch statements

default-case

要求 switch 语句中有 default 分支

dot-location

enforce consistent newlines before and after dots

dot-location

强制在点号之前和之后一致的换行

dot-notation

enforce dot notation whenever possible

dot-notation

强制尽可能地使用点号

eqeqeq

require the use of === and !==

eqeqeq

要求使用 ===!==

guard-for-in

require for-in loops to include an if statement

guard-for-in

要求 for-in 循环中有一个 if 语句

max-classes-per-file

enforce a maximum number of classes per file

max-classes-per-file

强制每个文件中包含的的类的最大数量

no-alert

disallow the use of alert, confirm, and prompt

no-alert

禁用 alertconfirmprompt

no-caller

disallow the use of arguments.caller or arguments.callee

no-caller

禁用 arguments.callerarguments.callee

no-case-declarations

disallow lexical declarations in case clauses

no-case-declarations

不允许在 case 子句中使用词法声明

no-div-regex

disallow division operators explicitly at the beginning of regular expressions

no-div-regex

禁止除法操作符显式的出现在正则表达式开始的位置

no-else-return

disallow else blocks after return statements in if statements

no-else-return

禁止 if 语句中 return 语句之后有 else

no-empty-function

disallow empty functions

no-empty-function

禁止出现空函数

no-empty-pattern

disallow empty destructuring patterns

no-empty-pattern

禁止使用空解构模式

no-eq-null

disallow null comparisons without type-checking operators

no-eq-null

禁止在没有类型检查操作符的情况下与 null 进行比较

no-eval

disallow the use of eval()

no-eval

禁用 eval()

no-extend-native

disallow extending native types

no-extend-native

禁止扩展原生类型

no-extra-bind

disallow unnecessary calls to .bind()

no-extra-bind

禁止不必要的 .bind() 调用

no-extra-label

disallow unnecessary labels

no-extra-label

禁用不必要的标签

no-fallthrough

disallow fallthrough of case statements

no-fallthrough

禁止 case 语句落空

no-floating-decimal

disallow leading or trailing decimal points in numeric literals

no-floating-decimal

禁止数字字面量中使用前导和末尾小数点

no-global-assign

disallow assignments to native objects or read-only global variables

no-global-assign

禁止对原生对象或只读的全局对象进行赋值

no-implicit-coercion

disallow shorthand type conversions

no-implicit-coercion

禁止使用短符号进行类型转换

no-implicit-globals

disallow variable and function declarations in the global scope

no-implicit-globals

禁止在全局范围内使用变量声明和 function 声明

no-implied-eval

disallow the use of eval()-like methods

no-implied-eval

禁止使用类似 eval() 的方法

no-invalid-this

disallow this keywords outside of classes or class-like objects

no-invalid-this

禁止 this 关键字出现在类和类对象之外

no-iterator

disallow the use of the __iterator__ property

no-iterator

禁用 __iterator__ 属性

no-labels

disallow labeled statements

no-labels

禁用标签语句

no-lone-blocks

disallow unnecessary nested blocks

no-lone-blocks

禁用不必要的嵌套块

no-loop-func

disallow function declarations that contain unsafe references inside loop statements

no-loop-func

禁止在循环语句中出现包含不安全引用的函数声明

no-magic-numbers

disallow magic numbers

no-magic-numbers

禁用魔术数字

no-multi-spaces

disallow multiple spaces

no-multi-spaces

禁止使用多个空格

no-multi-str

disallow multiline strings

no-multi-str

禁止使用多行字符串

no-new

disallow new operators outside of assignments or comparisons

no-new

禁止使用 new 以避免产生副作用

no-new-func

disallow new operators with the Function object

no-new-func

禁止对 Function 对象使用 new 操作符

no-new-wrappers

disallow new operators with the String, Number, and Boolean objects

no-new-wrappers

禁止对 StringNumberBoolean 使用 new 操作符

no-octal

disallow octal literals

no-octal

禁用八进制字面量

no-octal-escape

disallow octal escape sequences in string literals

no-octal-escape

禁止在字符串中使用八进制转义序列

no-param-reassign

disallow reassigning function parameters

no-param-reassign

禁止对 function 的参数进行重新赋值

no-proto

disallow the use of the __proto__ property

no-proto

禁用 __proto__ 属性

no-redeclare

disallow variable redeclaration

no-redeclare

禁止多次声明同一变量

no-restricted-properties

disallow certain properties on certain objects

no-restricted-properties

禁止使用对象的某些属性

no-return-assign

disallow assignment operators in return statements

no-return-assign

禁止在 return 语句中使用赋值语句

no-return-await

disallow unnecessary return await

no-return-await

禁用不必要的 return await

no-script-url

disallow javascript: urls

no-script-url

禁止使用 javascript: url

no-self-assign

disallow assignments where both sides are exactly the same

no-self-assign

禁止自我赋值

no-self-compare

disallow comparisons where both sides are exactly the same

no-self-compare

禁止自身比较

no-sequences

disallow comma operators

no-sequences

禁用逗号操作符

no-throw-literal

disallow throwing literals as exceptions

no-throw-literal

禁止抛出异常字面量

no-unmodified-loop-condition

disallow unmodified loop conditions

no-unmodified-loop-condition

禁用一成不变的循环条件

no-unused-expressions

disallow unused expressions

no-unused-expressions

禁止出现未使用过的表达式

no-unused-labels

disallow unused labels

no-unused-labels

禁用出现未使用过的标

no-useless-call

disallow unnecessary calls to .call() and .apply()

no-useless-call

禁止不必要的 .call().apply()

no-useless-catch

disallow unnecessary catch clauses

no-useless-catch

禁止不必要的 catch 子句

no-useless-concat

disallow unnecessary concatenation of literals or template literals

no-useless-concat

禁止不必要的字符串字面量或模板字面量的连接

no-useless-escape

disallow unnecessary escape characters

no-useless-escape

禁用不必要的转义字符

no-useless-return

disallow redundant return statements

no-useless-return

禁止多余的 return 语句

no-void

disallow void operators

no-void

禁用 void 操作符

no-warning-comments

disallow specified warning terms in comments

no-warning-comments

禁止在注释中使用特定的警告术语

no-with

disallow with statements

no-with

禁用 with 语句

prefer-named-capture-group

enforce using named capture group in regular expression

prefer-named-capture-group

建议在正则表达式中使用命名捕获组

prefer-promise-reject-errors

require using Error objects as Promise rejection reasons

prefer-promise-reject-errors

要求使用 Error 对象作为 Promise 拒绝的原因

radix

enforce the consistent use of the radix argument when using parseInt()

radix

强制在 parseInt() 使用基数参数

require-await

disallow async functions which have no await expression

require-await

禁止使用不带 await 表达式的 async 函数

require-unicode-regexp

enforce the use of u flag on RegExp

require-unicode-regexp

强制在 RegExp 上使用 u 标志

vars-on-top

require var declarations be placed at the top of their containing scope

vars-on-top

要求所有的 var 声明出现在它们所在的作用域顶部

wrap-iife

require parentheses around immediate function invocations

wrap-iife

要求 IIFE 使用括号括起来

yoda

require or disallow “Yoda” conditions

yoda

要求或禁止 “Yoda” 条件

Strict Mode

These rules relate to strict mode directives:

该规则与使用严格模式和严格模式指令有关:

strict

require or disallow strict mode directives

strict

要求或禁止使用严格模式指令

Variables

These rules relate to variable declarations:

这些规则与变量声明有关:

init-declarations

require or disallow initialization in variable declarations

init-declarations

要求或禁止 var 声明中的初始化

no-delete-var

disallow deleting variables

no-delete-var

禁止删除变量

no-label-var

disallow labels that share a name with a variable

no-label-var

不允许标签与变量同名

no-restricted-globals

disallow specified global variables

no-restricted-globals

禁用特定的全局变量

no-shadow

disallow variable declarations from shadowing variables declared in the outer scope

no-shadow

禁止变量声明与外层作用域的变量同名

no-shadow-restricted-names

disallow identifiers from shadowing restricted names

no-shadow-restricted-names

禁止将标识符定义为受限的名字

no-undef

disallow the use of undeclared variables unless mentioned in /*global */ comments

no-undef

禁用未声明的变量,除非它们在 /*global */ 注释中被提到

no-undef-init

disallow initializing variables to undefined

no-undef-init

禁止将变量初始化为 undefined

no-undefined

disallow the use of undefined as an identifier

no-undefined

禁止将 undefined 作为标识符

no-unused-vars

disallow unused variables

no-unused-vars

禁止出现未使用过的变量

no-use-before-define

disallow the use of variables before they are defined

no-use-before-define

禁止在变量定义之前使用它们

Node.js and CommonJS

These rules relate to code running in Node.js, or in browsers with CommonJS:

这些规则是关于Node.js 或 在浏览器中使用CommonJS 的:

callback-return

require return statements after callbacks

callback-return

强制数组方法的回调函数中有 return 语句

global-require

require require() calls to be placed at top-level module scope

global-require

要求 require() 出现在顶层模块作用域中

handle-callback-err

require error handling in callbacks

handle-callback-err

要求回调函数中有容错处理

no-buffer-constructor

disallow use of the Buffer() constructor

no-buffer-constructor

禁用 Buffer() 构造函数

no-mixed-requires

disallow require calls to be mixed with regular variable declarations

no-mixed-requires

禁止混合常规变量声明和 require 调用

no-new-require

disallow new operators with calls to require

no-new-require

禁止调用 require 时使用 new 操作符

no-path-concat

disallow string concatenation with __dirname and __filename

no-path-concat

禁止对 __dirname__filename 进行字符串连接

no-process-env

disallow the use of process.env

no-process-env

禁用 process.env

no-process-exit

disallow the use of process.exit()

no-process-exit

禁用 process.exit()

no-restricted-modules

disallow specified modules when loaded by require

no-restricted-modules

禁用通过 require 加载的指定模块

no-sync

disallow synchronous methods

no-sync

禁用同步方法

Stylistic Issues

These rules relate to style guidelines, and are therefore quite subjective:

这些规则是关于风格指南的,而且是非常主观的:

array-bracket-newline

enforce linebreaks after opening and before closing array brackets

array-bracket-newline

在数组开括号后和闭括号前强制换行

array-bracket-spacing

enforce consistent spacing inside array brackets

array-bracket-spacing

强制数组方括号中使用一致的空格

array-element-newline

enforce line breaks after each array element

array-element-newline

强制数组元素间出现换行

block-spacing

disallow or enforce spaces inside of blocks after opening block and before closing block

block-spacing

禁止或强制在代码块中开括号前和闭括号后有空格

brace-style

enforce consistent brace style for blocks

brace-style

强制在代码块中使用一致的大括号风格

camelcase

enforce camelcase naming convention

camelcase

强制使用骆驼拼写法命名约定

capitalized-comments

enforce or disallow capitalization of the first letter of a comment

capitalized-comments

强制或禁止对注释的第一个字母大写

comma-dangle

require or disallow trailing commas

comma-dangle

要求或禁止末尾逗号

comma-spacing

enforce consistent spacing before and after commas

comma-spacing

强制在逗号前后使用一致的空格

comma-style

enforce consistent comma style

comma-style

强制使用一致的逗号风格

computed-property-spacing

enforce consistent spacing inside computed property brackets

computed-property-spacing

强制在计算的属性的方括号中使用一致的空格

consistent-this

enforce consistent naming when capturing the current execution context

consistent-this

当获取当前执行环境的上下文时,强制使用一致的命名

eol-last

require or disallow newline at the end of files

eol-last

要求或禁止文件末尾存在空行

func-call-spacing

require or disallow spacing between function identifiers and their invocations

func-call-spacing

要求或禁止在函数标识符和其调用之间有空格

func-name-matching

require function names to match the name of the variable or property to which they are assigned

func-name-matching

要求函数名与赋值给它们的变量名或属性名相匹配

func-names

require or disallow named function expressions

func-names

要求或禁止使用命名的 function 表达式

func-style

enforce the consistent use of either function declarations or expressions

func-style

强制一致地使用 function 声明或表达式

function-paren-newline

enforce consistent line breaks inside function parentheses

function-paren-newline

强制在函数括号内使用一致的换行

id-blacklist

disallow specified identifiers

id-blacklist

禁用指定的标识符

id-length

enforce minimum and maximum identifier lengths

id-length

强制标识符的最小和最大长度

id-match

require identifiers to match a specified regular expression

id-match

要求标识符匹配一个指定的正则表达式

implicit-arrow-linebreak

enforce the location of arrow function bodies

implicit-arrow-linebreak

强制隐式返回的箭头函数体的位置

indent

enforce consistent indentation

indent

强制使用一致的缩进

jsx-quotes

enforce the consistent use of either double or single quotes in JSX attributes

jsx-quotes

强制在 JSX 属性中一致地使用双引号或单引号

key-spacing

enforce consistent spacing between keys and values in object literal properties

key-spacing

强制在对象字面量的属性中键和值之间使用一致的间距

keyword-spacing

enforce consistent spacing before and after keywords

keyword-spacing

强制在关键字前后使用一致的空格

line-comment-position

enforce position of line comments

line-comment-position

强制行注释的位置

linebreak-style

enforce consistent linebreak style

linebreak-style

强制使用一致的换行风格

lines-around-comment

require empty lines around comments

lines-around-comment

要求在注释周围有空行

lines-between-class-members

require or disallow an empty line between class members

lines-between-class-members

要求或禁止类成员之间出现空行

max-depth

enforce a maximum depth that blocks can be nested

max-depth

强制可嵌套的块的最大深度

max-len

enforce a maximum line length

max-len

强制一行的最大长度

max-lines

enforce a maximum number of lines per file

max-lines

强制最大行数

max-lines-per-function

enforce a maximum number of line of code in a function

max-lines-per-function

强制函数最大代码行数

max-nested-callbacks

enforce a maximum depth that callbacks can be nested

max-nested-callbacks

强制回调函数最大嵌套深度

max-params

enforce a maximum number of parameters in function definitions

max-params

强制函数定义中最多允许的参数数量

max-statements

enforce a maximum number of statements allowed in function blocks

max-statements

强制函数块最多允许的的语句数量

max-statements-per-line

enforce a maximum number of statements allowed per line

max-statements-per-line

强制每一行中所允许的最大语句数量

multiline-comment-style

enforce a particular style for multiline comments

multiline-comment-style

强制对多行注释使用特定风格

multiline-ternary

enforce newlines between operands of ternary expressions

multiline-ternary

要求或禁止在三元操作数中间换行

new-cap

require constructor names to begin with a capital letter

new-cap

要求构造函数首字母大写

new-parens

enforce or disallow parentheses when invoking a constructor with no arguments

new-parens

强制或禁止调用无参构造函数时有圆括号

newline-per-chained-call

require a newline after each call in a method chain

newline-per-chained-call

要求方法链中每个调用都有一个换行符

no-array-constructor

disallow Array constructors

no-array-constructor

禁用 Array 构造函数

no-bitwise

disallow bitwise operators

no-bitwise

禁用按位运算符

no-continue

disallow continue statements

no-continue

禁用 continue 语句

no-inline-comments

disallow inline comments after code

no-inline-comments

禁止在代码后使用内联注释

no-lonely-if

disallow if statements as the only statement in else blocks

no-lonely-if

禁止 if 作为唯一的语句出现在 else 语句中

no-mixed-operators

disallow mixed binary operators

no-mixed-operators

禁止混合使用不同的操作符

no-mixed-spaces-and-tabs

disallow mixed spaces and tabs for indentation

no-mixed-spaces-and-tabs

禁止空格和 tab 的混合缩进

no-multi-assign

disallow use of chained assignment expressions

no-multi-assign

禁止连续赋值

no-multiple-empty-lines

disallow multiple empty lines

no-multiple-empty-lines

禁止出现多行空行

no-negated-condition

disallow negated conditions

no-negated-condition

禁用否定的表达式

no-nested-ternary

disallow nested ternary expressions

no-nested-ternary

禁用嵌套的三元表达式

no-new-object

disallow Object constructors

no-new-object

禁用 Object 的构造函数

no-plusplus

disallow the unary operators ++ and --

no-plusplus

禁用一元操作符 ++--

no-restricted-syntax

disallow specified syntax

no-restricted-syntax

禁用特定的语法

no-tabs

disallow all tabs

no-tabs

禁用 tab

no-ternary

disallow ternary operators

no-ternary

禁用三元操作符

no-trailing-spaces

disallow trailing whitespace at the end of lines

no-trailing-spaces

禁用行尾空格

no-underscore-dangle

disallow dangling underscores in identifiers

no-underscore-dangle

禁止标识符中有悬空下划线

no-unneeded-ternary

disallow ternary operators when simpler alternatives exist

no-unneeded-ternary

禁止可以在有更简单的可替代的表达式时使用三元操作符

no-whitespace-before-property

disallow whitespace before properties

no-whitespace-before-property

禁止属性前有空白

nonblock-statement-body-position

enforce the location of single-line statements

nonblock-statement-body-position

强制单个语句的位置

object-curly-newline

enforce consistent line breaks inside braces

object-curly-newline

强制大括号内换行符的一致性

object-curly-spacing

enforce consistent spacing inside braces

object-curly-spacing

强制在大括号中使用一致的空格

object-property-newline

enforce placing object properties on separate lines

object-property-newline

强制将对象的属性放在不同的行上

one-var

enforce variables to be declared either together or separately in functions

one-var

强制函数中的变量要么一起声明要么分开声明

one-var-declaration-per-line

require or disallow newlines around variable declarations

one-var-declaration-per-line

要求或禁止在变量声明周围换行

operator-assignment

require or disallow assignment operator shorthand where possible

operator-assignment

要求或禁止在可能的情况下使用简化的赋值操作符

operator-linebreak

enforce consistent linebreak style for operators

operator-linebreak

强制操作符使用一致的换行符

padded-blocks

require or disallow padding within blocks

padded-blocks

要求或禁止块内填充

padding-line-between-statements

require or disallow padding lines between statements

padding-line-between-statements

要求或禁止在语句间填充空行

prefer-object-spread

disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.

prefer-object-spread

禁止使用以对象字面量作为第一个参数的 Object.assign,优先使用对象扩展。

quote-props

require quotes around object literal property names

quote-props

要求对象字面量属性名称用引号括起来

quotes

enforce the consistent use of either backticks, double, or single quotes

quotes

强制使用一致的反勾号、双引号或单引号

semi

require or disallow semicolons instead of ASI

semi

要求或禁止使用分号代替 ASI

semi-spacing

enforce consistent spacing before and after semicolons

semi-spacing

强制分号之前和之后使用一致的空格

semi-style

enforce location of semicolons

semi-style

强制分号的位置

sort-keys

require object keys to be sorted

sort-keys

要求对象属性按序排列

sort-vars

require variables within the same declaration block to be sorted

sort-vars

要求同一个声明块中的变量按顺序排列

space-before-blocks

enforce consistent spacing before blocks

space-before-blocks

强制在块之前使用一致的空格

space-before-function-paren

enforce consistent spacing before function definition opening parenthesis

space-before-function-paren

强制在 function的左括号之前使用一致的空格

space-in-parens

enforce consistent spacing inside parentheses

space-in-parens

强制在圆括号内使用一致的空格

space-infix-ops

require spacing around infix operators

space-infix-ops

要求操作符周围有空格

space-unary-ops

enforce consistent spacing before or after unary operators

space-unary-ops

强制在一元操作符前后使用一致的空格

spaced-comment

enforce consistent spacing after the // or /* in a comment

spaced-comment

强制在注释中 ///* 使用一致的空格

switch-colon-spacing

enforce spacing around colons of switch statements

switch-colon-spacing

强制在 switch 的冒号左右有空格

template-tag-spacing

require or disallow spacing between template tags and their literals

template-tag-spacing

要求或禁止在模板标记和它们的字面量之间有空格

unicode-bom

require or disallow Unicode byte order mark (BOM)

unicode-bom

要求或禁止 Unicode 字节顺序标记 (BOM)

wrap-regex

require parenthesis around regex literals

wrap-regex

要求正则表达式被括号括起来

ECMAScript 6

These rules relate to ES6, also known as ES2015:

这些规则只与 ES6 有关, 即通常所说的 ES2015:

arrow-body-style

require braces around arrow function bodies

arrow-body-style

要求箭头函数体使用大括号

arrow-parens

require parentheses around arrow function arguments

arrow-parens

要求箭头函数的参数使用圆括号

arrow-spacing

enforce consistent spacing before and after the arrow in arrow functions

arrow-spacing

强制箭头函数的箭头前后使用一致的空格

constructor-super

require super() calls in constructors

constructor-super

要求在构造函数中有 super() 的调用

generator-star-spacing

enforce consistent spacing around * operators in generator functions

generator-star-spacing

强制 generator 函数中 * 号周围使用一致的空格

no-class-assign

disallow reassigning class members

no-class-assign

禁止修改类声明的变量

no-confusing-arrow

disallow arrow functions where they could be confused with comparisons

no-confusing-arrow

禁止在可能与比较操作符相混淆的地方使用箭头函数

no-const-assign

disallow reassigning const variables

no-const-assign

禁止修改 const 声明的变量

no-dupe-class-members

disallow duplicate class members

no-dupe-class-members

禁止类成员中出现重复的名称

no-duplicate-imports

disallow duplicate module imports

no-duplicate-imports

禁止重复模块导入

no-new-symbol

disallow new operators with the Symbol object

no-new-symbol

禁止 Symbolnew 操作符和 new 一起使用

no-restricted-imports

disallow specified modules when loaded by import

no-restricted-imports

禁止使用指定的 import 加载的模块

no-this-before-super

disallow this/super before calling super() in constructors

no-this-before-super

禁止在构造函数中,在调用 super() 之前使用 thissuper

no-useless-computed-key

disallow unnecessary computed property keys in object literals

no-useless-computed-key

禁止在对象中使用不必要的计算属性

no-useless-constructor

disallow unnecessary constructors

no-useless-constructor

禁用不必要的构造函数

no-useless-rename

disallow renaming import, export, and destructured assignments to the same name

no-useless-rename

禁止在 import 和 export 和解构赋值时将引用重命名为相同的名字

no-var

require let or const instead of var

no-var

要求使用 letconst 而不是 var

object-shorthand

require or disallow method and property shorthand syntax for object literals

object-shorthand

要求或禁止对象字面量中方法和属性使用简写语法

prefer-arrow-callback

require using arrow functions for callbacks

prefer-arrow-callback

要求回调函数使用箭头函数

prefer-const

require const declarations for variables that are never reassigned after declared

prefer-const

要求使用 const 声明那些声明后不再被修改的变量

prefer-destructuring

require destructuring from arrays and/or objects

prefer-destructuring

优先使用数组和对象解构

prefer-numeric-literals

disallow parseInt() and Number.parseInt() in favor of binary, octal, and hexadecimal literals

prefer-numeric-literals

禁用 parseInt()Number.parseInt(),使用二进制,八进制和十六进制字面量

prefer-rest-params

require rest parameters instead of arguments

prefer-rest-params

要求使用剩余参数而不是 arguments

prefer-spread

require spread operators instead of .apply()

prefer-spread

要求使用扩展运算符而非 .apply()

prefer-template

require template literals instead of string concatenation

prefer-template

要求使用模板字面量而非字符串连接

require-yield

require generator functions to contain yield

require-yield

要求 generator 函数内有 yield

rest-spread-spacing

enforce spacing between rest and spread operators and their expressions

rest-spread-spacing

强制剩余和扩展运算符及其表达式之间有空格

sort-imports

enforce sorted import declarations within modules

sort-imports

强制模块内的 import 排序

symbol-description

require symbol descriptions

symbol-description

要求 symbol 描述

template-curly-spacing

require or disallow spacing around embedded expressions of template strings

template-curly-spacing

要求或禁止模板字符串中的嵌入表达式周围空格的使用

yield-star-spacing

require or disallow spacing around the * in yield* expressions

yield-star-spacing

强制在 yield* 表达式中 * 周围使用空格

Deprecated

These rules have been deprecated in accordance with the deprecation policy, and replaced by newer rules:

Removed

These rules from older versions of ESLint (before the deprecation policy existed) have been replaced by newer rules: