Versions

规则参考

ESLint 的规则按类型分组,以帮助你了解它们的目的。每条规则都有与之对应的表情符号:

Recommended

The "extends": "eslint:recommended" property in a configuration file enables this rule

🔧 Fixable

Some problems reported by this rule are automatically fixable by the --fix command line option

💡 hasSuggestions

Some problems reported by this rule are manually fixable by editor suggestions

Possible Problems

These rules relate to possible logic errors in code:

array-callback-return

Enforce return statements in callbacks of array methods

Categories:

constructor-super

Require `super()` calls in constructors

Categories:

Extends

for-direction

Enforce "for" loop update clause moving the counter in the right direction

Categories:

Extends

getter-return

Enforce `return` statements in getters

Categories:

Extends

no-async-promise-executor

Disallow using an async function as a Promise executor

Categories:

Extends

no-await-in-loop

Disallow `await` inside of loops

Categories:
no-class-assign

Disallow reassigning class members

Categories:

Extends

no-compare-neg-zero

Disallow comparing against -0

Categories:

Extends

no-cond-assign

Disallow assignment operators in conditional expressions

Categories:

Extends

no-const-assign

Disallow reassigning `const` variables

Categories:

Extends

no-constant-binary-expression

Disallow expressions where the operation doesn't affect the value

Categories:
no-constant-condition

Disallow constant expressions in conditions

Categories:

Extends

no-constructor-return

Disallow returning value from constructor

Categories:
no-control-regex

Disallow control characters in regular expressions

Categories:

Extends

no-debugger

Disallow the use of `debugger`

Categories:

Extends

no-dupe-args

Disallow duplicate arguments in `function` definitions

Categories:

Extends

no-dupe-class-members

Disallow duplicate class members

Categories:

Extends

no-dupe-else-if

Disallow duplicate conditions in if-else-if chains

Categories:

Extends

no-dupe-keys

Disallow duplicate keys in object literals

Categories:

Extends

no-duplicate-case

Disallow duplicate case labels

Categories:

Extends

no-duplicate-imports

Disallow duplicate module imports

Categories:
no-empty-character-class

Disallow empty character classes in regular expressions

Categories:

Extends

no-empty-pattern

Disallow empty destructuring patterns

Categories:

Extends

no-ex-assign

Disallow reassigning exceptions in `catch` clauses

Categories:

Extends

no-fallthrough

Disallow fallthrough of `case` statements

Categories:

Extends

no-func-assign

Disallow reassigning `function` declarations

Categories:

Extends

no-import-assign

Disallow assigning to imported bindings

Categories:

Extends

no-inner-declarations

Disallow variable or `function` declarations in nested blocks

Categories:

Extends

no-invalid-regexp

Disallow invalid regular expression strings in `RegExp` constructors

Categories:

Extends

no-loss-of-precision

Disallow literal numbers that lose precision

Categories:

Extends

no-misleading-character-class

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

Categories:

Extends

💡 Suggestions

no-new-native-nonconstructor

Disallow `new` operators with global non-constructor functions

Categories:
no-new-symbol

Disallow `new` operators with the `Symbol` object

Categories:

Extends

no-obj-calls

Disallow calling global object properties as functions

Categories:

Extends

no-promise-executor-return

Disallow returning values from Promise executor functions

Categories:

💡 Suggestions

no-prototype-builtins

Disallow calling some `Object.prototype` methods directly on objects

Categories:

Extends

no-self-assign

Disallow assignments where both sides are exactly the same

Categories:

Extends

no-self-compare

Disallow comparisons where both sides are exactly the same

Categories:
no-setter-return

Disallow returning values from setters

Categories:

Extends

no-sparse-arrays

Disallow sparse arrays

Categories:

Extends

no-template-curly-in-string

Disallow template literal placeholder syntax in regular strings

Categories:
no-this-before-super

Disallow `this`/`super` before calling `super()` in constructors

Categories:

Extends

no-undef

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

Categories:

Extends

no-unexpected-multiline

Disallow confusing multiline expressions

Categories:

Extends

no-unreachable

Disallow unreachable code after `return`, `throw`, `continue`, and `break` statements

Categories:

Extends

no-unreachable-loop

Disallow loops with a body that allows only one iteration

Categories:
no-unsafe-finally

Disallow control flow statements in `finally` blocks

Categories:

Extends

no-unsafe-negation

Disallow negating the left operand of relational operators

Categories:

Extends

💡 Suggestions

no-unsafe-optional-chaining

Disallow use of optional chaining in contexts where the `undefined` value is not allowed

Categories:

Extends

no-unused-vars

Disallow unused variables

Categories:

Extends

no-use-before-define

Disallow the use of variables before they are defined

Categories:
no-useless-backreference

Disallow useless backreferences in regular expressions

Categories:

Extends

require-atomic-updates

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

Categories:
use-isnan

Require calls to `isNaN()` when checking for `NaN`

Categories:

Extends

valid-typeof

Enforce comparing `typeof` expressions against valid strings

Categories:

Extends

💡 Suggestions

Suggestions

These rules suggest alternate ways of doing things:

accessor-pairs

Enforce getter and setter pairs in objects and classes

Categories:

arrow-body-style

Require braces around arrow function bodies

Categories:

🔧 Fix

block-scoped-var

Enforce the use of variables within the scope they are defined

Categories:
camelcase

Enforce camelcase naming convention

Categories:
capitalized-comments

Enforce or disallow capitalization of the first letter of a comment

Categories:

🔧 Fix

class-methods-use-this

Enforce that class methods utilize `this`

Categories:
complexity

Enforce a maximum cyclomatic complexity allowed in a program

Categories:
consistent-return

Require `return` statements to either always or never specify values

Categories:
consistent-this

Enforce consistent naming when capturing the current execution context

Categories:
curly

Enforce consistent brace style for all control statements

Categories:

🔧 Fix

default-case

Require `default` cases in `switch` statements

Categories:
default-case-last

Enforce default clauses in switch statements to be last

Categories:
default-param-last

Enforce default parameters to be last

Categories:
dot-notation

Enforce dot notation whenever possible

Categories:

🔧 Fix

eqeqeq

Require the use of `===` and `!==`

Categories:

🔧 Fix

func-name-matching

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

Categories:
func-names

Require or disallow named `function` expressions

Categories:
func-style

Enforce the consistent use of either `function` declarations or expressions

Categories:
grouped-accessor-pairs

Require grouped accessor pairs in object literals and classes

Categories:
guard-for-in

Require `for-in` loops to include an `if` statement

Categories:
id-denylist

Disallow specified identifiers

Categories:
id-length

Enforce minimum and maximum identifier lengths

Categories:
id-match

Require identifiers to match a specified regular expression

Categories:
init-declarations

Require or disallow initialization in variable declarations

Categories:
max-classes-per-file

Enforce a maximum number of classes per file

Categories:
max-depth

Enforce a maximum depth that blocks can be nested

Categories:
max-lines

Enforce a maximum number of lines per file

Categories:
max-lines-per-function

Enforce a maximum number of lines of code in a function

Categories:
max-nested-callbacks

Enforce a maximum depth that callbacks can be nested

Categories:
max-params

Enforce a maximum number of parameters in function definitions

Categories:
max-statements

Enforce a maximum number of statements allowed in function blocks

Categories:
multiline-comment-style

Enforce a particular style for multiline comments

Categories:

🔧 Fix

new-cap

Require constructor names to begin with a capital letter

Categories:
no-alert

Disallow the use of `alert`, `confirm`, and `prompt`

Categories:
no-array-constructor

Disallow `Array` constructors

Categories:
no-bitwise

Disallow bitwise operators

Categories:
no-caller

Disallow the use of `arguments.caller` or `arguments.callee`

Categories:
no-case-declarations

Disallow lexical declarations in case clauses

Categories:

Extends

no-confusing-arrow

Disallow arrow functions where they could be confused with comparisons

Categories:

🔧 Fix

no-console

Disallow the use of `console`

Categories:
no-continue

Disallow `continue` statements

Categories:
no-delete-var

Disallow deleting variables

Categories:

Extends

no-div-regex

Disallow equal signs explicitly at the beginning of regular expressions

Categories:

🔧 Fix

no-else-return

Disallow `else` blocks after `return` statements in `if` statements

Categories:

🔧 Fix

no-empty

Disallow empty block statements

Categories:

Extends

💡 Suggestions

no-empty-function

Disallow empty functions

Categories:
no-eq-null

Disallow `null` comparisons without type-checking operators

Categories:
no-eval

Disallow the use of `eval()`

Categories:
no-extend-native

Disallow extending native types

Categories:
no-extra-bind

Disallow unnecessary calls to `.bind()`

Categories:

🔧 Fix

no-extra-boolean-cast

Disallow unnecessary boolean casts

Categories:

Extends

🔧 Fix

no-extra-label

Disallow unnecessary labels

Categories:

🔧 Fix

no-extra-semi

Disallow unnecessary semicolons

Categories:

Extends

🔧 Fix

no-floating-decimal

Disallow leading or trailing decimal points in numeric literals

Categories:

🔧 Fix

no-global-assign

Disallow assignments to native objects or read-only global variables

Categories:

Extends

no-implicit-coercion

Disallow shorthand type conversions

Categories:

🔧 Fix

no-implicit-globals

Disallow declarations in the global scope

Categories:
no-implied-eval

Disallow the use of `eval()`-like methods

Categories:
no-inline-comments

Disallow inline comments after code

Categories:
no-invalid-this

Disallow use of `this` in contexts where the value of `this` is `undefined`

Categories:
no-iterator

Disallow the use of the `__iterator__` property

Categories:
no-label-var

Disallow labels that share a name with a variable

Categories:
no-labels

Disallow labeled statements

Categories:
no-lone-blocks

Disallow unnecessary nested blocks

Categories:
no-lonely-if

Disallow `if` statements as the only statement in `else` blocks

Categories:

🔧 Fix

no-loop-func

Disallow function declarations that contain unsafe references inside loop statements

Categories:
no-magic-numbers

Disallow magic numbers

Categories:
no-mixed-operators

Disallow mixed binary operators

Categories:
no-multi-assign

Disallow use of chained assignment expressions

Categories:
no-multi-str

Disallow multiline strings

Categories:
no-negated-condition

Disallow negated conditions

Categories:
no-nested-ternary

Disallow nested ternary expressions

Categories:
no-new

Disallow `new` operators outside of assignments or comparisons

Categories:
no-new-func

Disallow `new` operators with the `Function` object

Categories:
no-new-object

Disallow `Object` constructors

Categories:
no-new-wrappers

Disallow `new` operators with the `String`, `Number`, and `Boolean` objects

Categories:
no-nonoctal-decimal-escape

Disallow `\8` and `\9` escape sequences in string literals

Categories:

Extends

💡 Suggestions

no-octal

Disallow octal literals

Categories:

Extends

no-octal-escape

Disallow octal escape sequences in string literals

Categories:
no-param-reassign

Disallow reassigning `function` parameters

Categories:
no-plusplus

Disallow the unary operators `++` and `--`

Categories:
no-proto

Disallow the use of the `__proto__` property

Categories:
no-redeclare

Disallow variable redeclaration

Categories:

Extends

no-regex-spaces

Disallow multiple spaces in regular expressions

Categories:

Extends

🔧 Fix

no-restricted-exports

Disallow specified names in exports

Categories:
no-restricted-globals

Disallow specified global variables

Categories:
no-restricted-imports

Disallow specified modules when loaded by `import`

Categories:
no-restricted-properties

Disallow certain properties on certain objects

Categories:
no-return-assign

Disallow assignment operators in `return` statements

Categories:
no-script-url

Disallow `javascript:` urls

Categories:
no-sequences

Disallow comma operators

Categories:
no-shadow

Disallow variable declarations from shadowing variables declared in the outer scope

Categories:
no-shadow-restricted-names

Disallow identifiers from shadowing restricted names

Categories:

Extends

no-ternary

Disallow ternary operators

Categories:
no-throw-literal

Disallow throwing literals as exceptions

Categories:
no-undef-init

Disallow initializing variables to `undefined`

Categories:

🔧 Fix

no-undefined

Disallow the use of `undefined` as an identifier

Categories:
no-underscore-dangle

Disallow dangling underscores in identifiers

Categories:
no-unneeded-ternary

Disallow ternary operators when simpler alternatives exist

Categories:

🔧 Fix

no-unused-labels

Disallow unused labels

Categories:

Extends

🔧 Fix

no-useless-call

Disallow unnecessary calls to `.call()` and `.apply()`

Categories:
no-useless-catch

Disallow unnecessary `catch` clauses

Categories:

Extends

no-useless-computed-key

Disallow unnecessary computed property keys in objects and classes

Categories:

🔧 Fix

no-useless-concat

Disallow unnecessary concatenation of literals or template literals

Categories:
no-useless-escape

Disallow unnecessary escape characters

Categories:

Extends

💡 Suggestions

no-useless-rename

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

Categories:

🔧 Fix

no-useless-return

Disallow redundant return statements

Categories:

🔧 Fix

no-var

Require `let` or `const` instead of `var`

Categories:

🔧 Fix

no-void

Disallow `void` operators

Categories:
no-warning-comments

Disallow specified warning terms in comments

Categories:
no-with

Disallow `with` statements

Categories:

Extends

object-shorthand

Require or disallow method and property shorthand syntax for object literals

Categories:

🔧 Fix

one-var

Enforce variables to be declared either together or separately in functions

Categories:

🔧 Fix

operator-assignment

Require or disallow assignment operator shorthand where possible

Categories:

🔧 Fix

prefer-arrow-callback

Require using arrow functions for callbacks

Categories:

🔧 Fix

prefer-const

Require `const` declarations for variables that are never reassigned after declared

Categories:

🔧 Fix

prefer-destructuring

Require destructuring from arrays and/or objects

Categories:

🔧 Fix

prefer-named-capture-group

Enforce using named capture group in regular expression

Categories:

💡 Suggestions

prefer-numeric-literals

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

Categories:

🔧 Fix

prefer-object-has-own

Disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()`

Categories:

🔧 Fix

prefer-object-spread

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

Categories:

🔧 Fix

prefer-regex-literals

Disallow use of the `RegExp` constructor in favor of regular expression literals

Categories:

💡 Suggestions

prefer-rest-params

Require rest parameters instead of `arguments`

Categories:
prefer-spread

Require spread operators instead of `.apply()`

Categories:
prefer-template

Require template literals instead of string concatenation

Categories:

🔧 Fix

quote-props

Require quotes around object literal property names

Categories:

🔧 Fix

radix

Enforce the consistent use of the radix argument when using `parseInt()`

Categories:

💡 Suggestions

require-await

Disallow async functions which have no `await` expression

Categories:
require-unicode-regexp

Enforce the use of `u` or `v` flag on RegExp

Categories:

💡 Suggestions

require-yield

Require generator functions to contain `yield`

Categories:

Extends

sort-imports

Enforce sorted import declarations within modules

Categories:

🔧 Fix

sort-keys

Require object keys to be sorted

Categories:
sort-vars

Require variables within the same declaration block to be sorted

Categories:

🔧 Fix

spaced-comment

Enforce consistent spacing after the `//` or `/*` in a comment

Categories:

🔧 Fix

strict

Require or disallow strict mode directives

Categories:

🔧 Fix

symbol-description

Require symbol descriptions

Categories:
vars-on-top

Require `var` declarations be placed at the top of their containing scope

Categories:
yoda

Require or disallow "Yoda" conditions

Categories:

🔧 Fix

Layout & Formatting

These rules care about how the code looks rather than how it executes:

array-bracket-newline

Enforce linebreaks after opening and before closing array brackets

Categories:

🔧 Fix

array-bracket-spacing

Enforce consistent spacing inside array brackets

Categories:

🔧 Fix

array-element-newline

Enforce line breaks after each array element

Categories:

🔧 Fix

arrow-parens

Require parentheses around arrow function arguments

Categories:

🔧 Fix

arrow-spacing

Enforce consistent spacing before and after the arrow in arrow functions

Categories:

🔧 Fix

block-spacing

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

Categories:

🔧 Fix

brace-style

Enforce consistent brace style for blocks

Categories:

🔧 Fix

comma-dangle

Require or disallow trailing commas

Categories:

🔧 Fix

comma-spacing

Enforce consistent spacing before and after commas

Categories:

🔧 Fix

comma-style

Enforce consistent comma style

Categories:

🔧 Fix

computed-property-spacing

Enforce consistent spacing inside computed property brackets

Categories:

🔧 Fix

dot-location

Enforce consistent newlines before and after dots

Categories:

🔧 Fix

eol-last

Require or disallow newline at the end of files

Categories:

🔧 Fix

func-call-spacing

Require or disallow spacing between function identifiers and their invocations

Categories:

🔧 Fix

function-paren-newline

Enforce consistent line breaks inside function parentheses

Categories:

🔧 Fix

generator-star-spacing

Enforce consistent spacing around `*` operators in generator functions

Categories:

🔧 Fix

implicit-arrow-linebreak

Enforce the location of arrow function bodies

Categories:

🔧 Fix

indent

Enforce consistent indentation

Categories:

🔧 Fix

jsx-quotes

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

Categories:

🔧 Fix

key-spacing

Enforce consistent spacing between keys and values in object literal properties

Categories:

🔧 Fix

keyword-spacing

Enforce consistent spacing before and after keywords

Categories:

🔧 Fix

line-comment-position

Enforce position of line comments

Categories:
linebreak-style

Enforce consistent linebreak style

Categories:

🔧 Fix

lines-around-comment

Require empty lines around comments

Categories:

🔧 Fix

lines-between-class-members

Require or disallow an empty line between class members

Categories:

🔧 Fix

max-len

Enforce a maximum line length

Categories:
max-statements-per-line

Enforce a maximum number of statements allowed per line

Categories:
multiline-ternary

Enforce newlines between operands of ternary expressions

Categories:

🔧 Fix

new-parens

Enforce or disallow parentheses when invoking a constructor with no arguments

Categories:

🔧 Fix

newline-per-chained-call

Require a newline after each call in a method chain

Categories:

🔧 Fix

no-extra-parens

Disallow unnecessary parentheses

Categories:

🔧 Fix

no-mixed-spaces-and-tabs

Disallow mixed spaces and tabs for indentation

Categories:

Extends

no-multi-spaces

Disallow multiple spaces

Categories:

🔧 Fix

no-tabs

Disallow all tabs

Categories:
no-trailing-spaces

Disallow trailing whitespace at the end of lines

Categories:

🔧 Fix

object-curly-newline

Enforce consistent line breaks after opening and before closing braces

Categories:

🔧 Fix

object-curly-spacing

Enforce consistent spacing inside braces

Categories:

🔧 Fix

object-property-newline

Enforce placing object properties on separate lines

Categories:

🔧 Fix

operator-linebreak

Enforce consistent linebreak style for operators

Categories:

🔧 Fix

padded-blocks

Require or disallow padding within blocks

Categories:

🔧 Fix

quotes

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

Categories:

🔧 Fix

rest-spread-spacing

Enforce spacing between rest and spread operators and their expressions

Categories:

🔧 Fix

semi

Require or disallow semicolons instead of ASI

Categories:

🔧 Fix

semi-spacing

Enforce consistent spacing before and after semicolons

Categories:

🔧 Fix

semi-style

Enforce location of semicolons

Categories:

🔧 Fix

space-before-blocks

Enforce consistent spacing before blocks

Categories:

🔧 Fix

space-before-function-paren

Enforce consistent spacing before `function` definition opening parenthesis

Categories:

🔧 Fix

space-in-parens

Enforce consistent spacing inside parentheses

Categories:

🔧 Fix

space-infix-ops

Require spacing around infix operators

Categories:

🔧 Fix

space-unary-ops

Enforce consistent spacing before or after unary operators

Categories:

🔧 Fix

switch-colon-spacing

Enforce spacing around colons of switch statements

Categories:

🔧 Fix

template-curly-spacing

Require or disallow spacing around embedded expressions of template strings

Categories:

🔧 Fix

template-tag-spacing

Require or disallow spacing between template tags and their literals

Categories:

🔧 Fix

unicode-bom

Require or disallow Unicode byte order mark (BOM)

Categories:

🔧 Fix

wrap-iife

Require parentheses around immediate `function` invocations

Categories:

🔧 Fix

wrap-regex

Require parenthesis around regex literals

Categories:

🔧 Fix

yield-star-spacing

Require or disallow spacing around the `*` in `yield*` expressions

Categories:

🔧 Fix

Deprecated

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

callback-return deprecated

Categories:

🔧 Fix

💡 Suggestions

global-require deprecated

Categories:

🔧 Fix

💡 Suggestions

handle-callback-err deprecated

Categories:

🔧 Fix

💡 Suggestions

id-blacklist deprecated

Replaced by id-denylist

Categories:

🔧 Fix

💡 Suggestions

indent-legacy deprecated

Replaced by indent

Categories:

🔧 Fix

💡 Suggestions

no-buffer-constructor deprecated

Categories:

🔧 Fix

💡 Suggestions

no-catch-shadow deprecated

Replaced by no-shadow

Categories:

🔧 Fix

💡 Suggestions

no-mixed-requires deprecated

Categories:

🔧 Fix

💡 Suggestions

no-native-reassign deprecated

Replaced by no-global-assign

Categories:

🔧 Fix

💡 Suggestions

no-negated-in-lhs deprecated

Replaced by no-unsafe-negation

Categories:

🔧 Fix

💡 Suggestions

no-new-require deprecated

Categories:

🔧 Fix

💡 Suggestions

no-path-concat deprecated

Categories:

🔧 Fix

💡 Suggestions

no-process-env deprecated

Categories:

🔧 Fix

💡 Suggestions

no-process-exit deprecated

Categories:

🔧 Fix

💡 Suggestions

no-restricted-modules deprecated

Categories:

🔧 Fix

💡 Suggestions

no-return-await deprecated

Categories:

🔧 Fix

💡 Suggestions

no-spaced-func deprecated

Replaced by func-call-spacing

Categories:

🔧 Fix

💡 Suggestions

no-sync deprecated

Categories:

🔧 Fix

💡 Suggestions

prefer-reflect deprecated

Categories:

🔧 Fix

💡 Suggestions

require-jsdoc deprecated

Categories:

🔧 Fix

💡 Suggestions

valid-jsdoc deprecated

Categories:

🔧 Fix

💡 Suggestions

Removed

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

global-strict removed

Replaced by strict

Categories:

🔧 Fix

💡 Suggestions

no-comma-dangle removed

Replaced by comma-dangle

Categories:

🔧 Fix

💡 Suggestions

no-empty-label removed

Replaced by no-labels

Categories:

🔧 Fix

💡 Suggestions

no-extra-strict removed

Replaced by strict

Categories:

🔧 Fix

💡 Suggestions

no-reserved-keys removed

Replaced by quote-props

Categories:

🔧 Fix

💡 Suggestions

no-space-before-semi removed

Replaced by semi-spacing

Categories:

🔧 Fix

💡 Suggestions

no-wrap-func removed

Replaced by no-extra-parens

Categories:

🔧 Fix

💡 Suggestions

space-after-keywords removed

Replaced by keyword-spacing

Categories:

🔧 Fix

💡 Suggestions

space-before-keywords removed

Replaced by keyword-spacing

Categories:

🔧 Fix

💡 Suggestions

space-return-throw-case removed

Replaced by keyword-spacing

Categories:

🔧 Fix

💡 Suggestions

space-unary-word-ops removed

Replaced by space-unary-ops

Categories:

🔧 Fix

💡 Suggestions

spaced-line-comment removed

Replaced by spaced-comment

Categories:

🔧 Fix

💡 Suggestions

更改语言