Rules

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

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.

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

Possible Errors

These rules relate to possible syntax or logic errors in JavaScript code:
for-directionenforce "for" loop update clause moving the counter in the right direction.
getter-returnenforce `return` statements in getters
no-async-promise-executordisallow using an async function as a Promise executor
no-await-in-loopdisallow `await` inside of loops
no-compare-neg-zerodisallow comparing against -0
no-cond-assigndisallow assignment operators in conditional expressions
no-consoledisallow the use of `console`
no-constant-conditiondisallow constant expressions in conditions
no-control-regexdisallow control characters in regular expressions
no-debuggerdisallow the use of `debugger`
no-dupe-argsdisallow duplicate arguments in `function` definitions
no-dupe-else-ifdisallow duplicate conditions in if-else-if chains
no-dupe-keysdisallow duplicate keys in object literals
no-duplicate-casedisallow duplicate case labels
no-emptydisallow empty block statements
no-empty-character-classdisallow empty character classes in regular expressions
no-ex-assigndisallow reassigning exceptions in `catch` clauses
no-extra-boolean-castdisallow unnecessary boolean casts
no-extra-parensdisallow unnecessary parentheses
no-extra-semidisallow unnecessary semicolons
no-func-assigndisallow reassigning `function` declarations
no-import-assigndisallow assigning to imported bindings
no-inner-declarationsdisallow variable or `function` declarations in nested blocks
no-invalid-regexpdisallow invalid regular expression strings in `RegExp` constructors
no-irregular-whitespacedisallow irregular whitespace
no-loss-of-precisiondisallow literal numbers that lose precision
no-misleading-character-classdisallow characters which are made with multiple code points in character class syntax
no-obj-callsdisallow calling global object properties as functions
no-promise-executor-returndisallow returning values from Promise executor functions
no-prototype-builtinsdisallow calling some `Object.prototype` methods directly on objects
no-regex-spacesdisallow multiple spaces in regular expressions
no-setter-returndisallow returning values from setters
no-sparse-arraysdisallow sparse arrays
no-template-curly-in-stringdisallow template literal placeholder syntax in regular strings
no-unexpected-multilinedisallow confusing multiline expressions
no-unreachabledisallow unreachable code after `return`, `throw`, `continue`, and `break` statements
no-unreachable-loopdisallow loops with a body that allows only one iteration
no-unsafe-finallydisallow control flow statements in `finally` blocks
no-unsafe-negationdisallow negating the left operand of relational operators
no-useless-backreferencedisallow useless backreferences in regular expressions
require-atomic-updatesdisallow assignments that can lead to race conditions due to usage of `await` or `yield`
use-isnanrequire calls to `isNaN()` when checking for `NaN`
valid-typeofenforce comparing `typeof` expressions against valid strings

Best Practices

These rules relate to better ways of doing things to help you avoid problems:
accessor-pairsenforce getter and setter pairs in objects and classes
array-callback-returnenforce `return` statements in callbacks of array methods
block-scoped-varenforce the use of variables within the scope they are defined
class-methods-use-thisenforce that class methods utilize `this`
complexityenforce a maximum cyclomatic complexity allowed in a program
consistent-returnrequire `return` statements to either always or never specify values
curlyenforce consistent brace style for all control statements
default-caserequire `default` cases in `switch` statements
default-case-lastenforce default clauses in switch statements to be last
default-param-lastenforce default parameters to be last
dot-locationenforce consistent newlines before and after dots
dot-notationenforce dot notation whenever possible
eqeqeqrequire the use of `===` and `!==`
grouped-accessor-pairsrequire grouped accessor pairs in object literals and classes
guard-for-inrequire `for-in` loops to include an `if` statement
max-classes-per-fileenforce a maximum number of classes per file
no-alertdisallow the use of `alert`, `confirm`, and `prompt`
no-callerdisallow the use of `arguments.caller` or `arguments.callee`
no-case-declarationsdisallow lexical declarations in case clauses
no-constructor-returndisallow returning value from constructor
no-div-regexdisallow division operators explicitly at the beginning of regular expressions
no-else-returndisallow `else` blocks after `return` statements in `if` statements
no-empty-functiondisallow empty functions
no-empty-patterndisallow empty destructuring patterns
no-eq-nulldisallow `null` comparisons without type-checking operators
no-evaldisallow the use of `eval()`
no-extend-nativedisallow extending native types
no-extra-binddisallow unnecessary calls to `.bind()`
no-extra-labeldisallow unnecessary labels
no-fallthroughdisallow fallthrough of `case` statements
no-floating-decimaldisallow leading or trailing decimal points in numeric literals
no-global-assigndisallow assignments to native objects or read-only global variables
no-implicit-coerciondisallow shorthand type conversions
no-implicit-globalsdisallow declarations in the global scope
no-implied-evaldisallow the use of `eval()`-like methods
no-invalid-thisdisallow `this` keywords outside of classes or class-like objects
no-iteratordisallow the use of the `__iterator__` property
no-labelsdisallow labeled statements
no-lone-blocksdisallow unnecessary nested blocks
no-loop-funcdisallow function declarations that contain unsafe references inside loop statements
no-magic-numbersdisallow magic numbers
no-multi-spacesdisallow multiple spaces
no-multi-strdisallow multiline strings
no-newdisallow `new` operators outside of assignments or comparisons
no-new-funcdisallow `new` operators with the `Function` object
no-new-wrappersdisallow `new` operators with the `String`, `Number`, and `Boolean` objects
no-octaldisallow octal literals
no-octal-escapedisallow octal escape sequences in string literals
no-param-reassigndisallow reassigning `function` parameters
no-protodisallow the use of the `__proto__` property
no-redeclaredisallow variable redeclaration
no-restricted-propertiesdisallow certain properties on certain objects
no-return-assigndisallow assignment operators in `return` statements
no-return-awaitdisallow unnecessary `return await`
no-script-urldisallow `javascript:` urls
no-self-assigndisallow assignments where both sides are exactly the same
no-self-comparedisallow comparisons where both sides are exactly the same
no-sequencesdisallow comma operators
no-throw-literaldisallow throwing literals as exceptions
no-unmodified-loop-conditiondisallow unmodified loop conditions
no-unused-expressionsdisallow unused expressions
no-unused-labelsdisallow unused labels
no-useless-calldisallow unnecessary calls to `.call()` and `.apply()`
no-useless-catchdisallow unnecessary `catch` clauses
no-useless-concatdisallow unnecessary concatenation of literals or template literals
no-useless-escapedisallow unnecessary escape characters
no-useless-returndisallow redundant return statements
no-voiddisallow `void` operators
no-warning-commentsdisallow specified warning terms in comments
no-withdisallow `with` statements
prefer-named-capture-groupenforce using named capture group in regular expression
prefer-promise-reject-errorsrequire using Error objects as Promise rejection reasons
prefer-regex-literalsdisallow use of the `RegExp` constructor in favor of regular expression literals
radixenforce the consistent use of the radix argument when using `parseInt()`
require-awaitdisallow async functions which have no `await` expression
require-unicode-regexpenforce the use of `u` flag on RegExp
vars-on-toprequire `var` declarations be placed at the top of their containing scope
wrap-iiferequire parentheses around immediate `function` invocations
yodarequire or disallow "Yoda" conditions

Strict Mode

These rules relate to strict mode directives:
strictrequire or disallow strict mode directives

Variables

These rules relate to variable declarations:
init-declarationsrequire or disallow initialization in variable declarations
no-delete-vardisallow deleting variables
no-label-vardisallow labels that share a name with a variable
no-restricted-globalsdisallow specified global variables
no-shadowdisallow variable declarations from shadowing variables declared in the outer scope
no-shadow-restricted-namesdisallow identifiers from shadowing restricted names
no-undefdisallow the use of undeclared variables unless mentioned in `/*global */` comments
no-undef-initdisallow initializing variables to `undefined`
no-undefineddisallow the use of `undefined` as an identifier
no-unused-varsdisallow unused variables
no-use-before-definedisallow the use of variables before they are defined

Stylistic Issues

These rules relate to style guidelines, and are therefore quite subjective:
array-bracket-newlineenforce linebreaks after opening and before closing array brackets
array-bracket-spacingenforce consistent spacing inside array brackets
array-element-newlineenforce line breaks after each array element
block-spacingdisallow or enforce spaces inside of blocks after opening block and before closing block
brace-styleenforce consistent brace style for blocks
camelcaseenforce camelcase naming convention
capitalized-commentsenforce or disallow capitalization of the first letter of a comment
comma-danglerequire or disallow trailing commas
comma-spacingenforce consistent spacing before and after commas
comma-styleenforce consistent comma style
computed-property-spacingenforce consistent spacing inside computed property brackets
consistent-thisenforce consistent naming when capturing the current execution context
eol-lastrequire or disallow newline at the end of files
func-call-spacingrequire or disallow spacing between function identifiers and their invocations
func-name-matchingrequire function names to match the name of the variable or property to which they are assigned
func-namesrequire or disallow named `function` expressions
func-styleenforce the consistent use of either `function` declarations or expressions
function-call-argument-newlineenforce line breaks between arguments of a function call
function-paren-newlineenforce consistent line breaks inside function parentheses
id-denylistdisallow specified identifiers
id-lengthenforce minimum and maximum identifier lengths
id-matchrequire identifiers to match a specified regular expression
implicit-arrow-linebreakenforce the location of arrow function bodies
indentenforce consistent indentation
jsx-quotesenforce the consistent use of either double or single quotes in JSX attributes
key-spacingenforce consistent spacing between keys and values in object literal properties
keyword-spacingenforce consistent spacing before and after keywords
line-comment-positionenforce position of line comments
linebreak-styleenforce consistent linebreak style
lines-around-commentrequire empty lines around comments
lines-between-class-membersrequire or disallow an empty line between class members
max-depthenforce a maximum depth that blocks can be nested
max-lenenforce a maximum line length
max-linesenforce a maximum number of lines per file
max-lines-per-functionenforce a maximum number of line of code in a function
max-nested-callbacksenforce a maximum depth that callbacks can be nested
max-paramsenforce a maximum number of parameters in function definitions
max-statementsenforce a maximum number of statements allowed in function blocks
max-statements-per-lineenforce a maximum number of statements allowed per line
multiline-comment-styleenforce a particular style for multiline comments
multiline-ternaryenforce newlines between operands of ternary expressions
new-caprequire constructor names to begin with a capital letter
new-parensenforce or disallow parentheses when invoking a constructor with no arguments
newline-per-chained-callrequire a newline after each call in a method chain
no-array-constructordisallow `Array` constructors
no-bitwisedisallow bitwise operators
no-continuedisallow `continue` statements
no-inline-commentsdisallow inline comments after code
no-lonely-ifdisallow `if` statements as the only statement in `else` blocks
no-mixed-operatorsdisallow mixed binary operators
no-mixed-spaces-and-tabsdisallow mixed spaces and tabs for indentation
no-multi-assigndisallow use of chained assignment expressions
no-multiple-empty-linesdisallow multiple empty lines
no-negated-conditiondisallow negated conditions
no-nested-ternarydisallow nested ternary expressions
no-new-objectdisallow `Object` constructors
no-plusplusdisallow the unary operators `++` and `--`
no-restricted-syntaxdisallow specified syntax
no-tabsdisallow all tabs
no-ternarydisallow ternary operators
no-trailing-spacesdisallow trailing whitespace at the end of lines
no-underscore-dangledisallow dangling underscores in identifiers
no-unneeded-ternarydisallow ternary operators when simpler alternatives exist
no-whitespace-before-propertydisallow whitespace before properties
nonblock-statement-body-positionenforce the location of single-line statements
object-curly-newlineenforce consistent line breaks inside braces
object-curly-spacingenforce consistent spacing inside braces
object-property-newlineenforce placing object properties on separate lines
one-varenforce variables to be declared either together or separately in functions
one-var-declaration-per-linerequire or disallow newlines around variable declarations
operator-assignmentrequire or disallow assignment operator shorthand where possible
operator-linebreakenforce consistent linebreak style for operators
padded-blocksrequire or disallow padding within blocks
padding-line-between-statementsrequire or disallow padding lines between statements
prefer-exponentiation-operatordisallow the use of `Math.pow` in favor of the `**` operator
prefer-object-spreaddisallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead.
quote-propsrequire quotes around object literal property names
quotesenforce the consistent use of either backticks, double, or single quotes
semirequire or disallow semicolons instead of ASI
semi-spacingenforce consistent spacing before and after semicolons
semi-styleenforce location of semicolons
sort-keysrequire object keys to be sorted
sort-varsrequire variables within the same declaration block to be sorted
space-before-blocksenforce consistent spacing before blocks
space-before-function-parenenforce consistent spacing before `function` definition opening parenthesis
space-in-parensenforce consistent spacing inside parentheses
space-infix-opsrequire spacing around infix operators
space-unary-opsenforce consistent spacing before or after unary operators
spaced-commentenforce consistent spacing after the `//` or `/*` in a comment
switch-colon-spacingenforce spacing around colons of switch statements
template-tag-spacingrequire or disallow spacing between template tags and their literals
unicode-bomrequire or disallow Unicode byte order mark (BOM)
wrap-regexrequire parenthesis around regex literals

ECMAScript 6

These rules relate to ES6, also known as ES2015:
arrow-body-stylerequire braces around arrow function bodies
arrow-parensrequire parentheses around arrow function arguments
arrow-spacingenforce consistent spacing before and after the arrow in arrow functions
constructor-superrequire `super()` calls in constructors
generator-star-spacingenforce consistent spacing around `*` operators in generator functions
no-class-assigndisallow reassigning class members
no-confusing-arrowdisallow arrow functions where they could be confused with comparisons
no-const-assigndisallow reassigning `const` variables
no-dupe-class-membersdisallow duplicate class members
no-duplicate-importsdisallow duplicate module imports
no-new-symboldisallow `new` operators with the `Symbol` object
no-restricted-exportsdisallow specified names in exports
no-restricted-importsdisallow specified modules when loaded by `import`
no-this-before-superdisallow `this`/`super` before calling `super()` in constructors
no-useless-computed-keydisallow unnecessary computed property keys in objects and classes
no-useless-constructordisallow unnecessary constructors
no-useless-renamedisallow renaming import, export, and destructured assignments to the same name
no-varrequire `let` or `const` instead of `var`
object-shorthandrequire or disallow method and property shorthand syntax for object literals
prefer-arrow-callbackrequire using arrow functions for callbacks
prefer-constrequire `const` declarations for variables that are never reassigned after declared
prefer-destructuringrequire destructuring from arrays and/or objects
prefer-numeric-literalsdisallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals
prefer-rest-paramsrequire rest parameters instead of `arguments`
prefer-spreadrequire spread operators instead of `.apply()`
prefer-templaterequire template literals instead of string concatenation
require-yieldrequire generator functions to contain `yield`
rest-spread-spacingenforce spacing between rest and spread operators and their expressions
sort-importsenforce sorted import declarations within modules
symbol-descriptionrequire symbol descriptions
template-curly-spacingrequire or disallow spacing around embedded expressions of template strings
yield-star-spacingrequire or disallow spacing around the `*` in `yield*` expressions

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:
Js中文网,专注分享前端最新技术、大厂面试题、聊点程序员轶事、职场感悟,做前端技术的传播者.

加入前端布道师交流群

扫描二维码回复 加群 学习,与大厂大佬讨论技术.