Versions

Rules Reference

Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis denoting:

โœ… 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:

๐Ÿ’ก Suggestions

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-irregular-whitespace

Disallow irregular whitespace

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

๐Ÿ’ก Suggestions

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:
logical-assignment-operators

Require or disallow logical assignment operator shorthand

Categories:

๐Ÿ”ง Fix

๐Ÿ’ก Suggestions

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:

๐Ÿ’ก Suggestions

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-console

Disallow the use of console

Categories:

๐Ÿ’ก Suggestions

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-empty-static-block

Disallow empty static blocks

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-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-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-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-object-constructor

Disallow calls to the Object constructor without an argument

Categories:

๐Ÿ’ก 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-restricted-syntax

Disallow specified syntax

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-expressions

Disallow unused expressions

Categories:
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-constructor

Disallow unnecessary constructors

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-exponentiation-operator

Disallow the use of Math.pow in favor of the ** operator

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-promise-reject-errors

Require using Error objects as Promise rejection reasons

Categories:
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

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

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:

line-comment-position

Enforce position of line comments

Categories:
unicode-bom

Require or disallow Unicode byte order mark (BOM)

Categories:

๐Ÿ”ง Fix

Deprecated

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

array-bracket-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

array-bracket-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

array-element-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

arrow-parens deprecated

Categories:

โŒ

๐Ÿ”ง Fix

arrow-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

block-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

brace-style deprecated

Categories:

โŒ

๐Ÿ”ง Fix

callback-return deprecated

Categories:

โŒ

comma-dangle deprecated

Categories:

โŒ

๐Ÿ”ง Fix

comma-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

comma-style deprecated

Categories:

โŒ

๐Ÿ”ง Fix

computed-property-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

dot-location deprecated

Categories:

โŒ

๐Ÿ”ง Fix

eol-last deprecated

Categories:

โŒ

๐Ÿ”ง Fix

func-call-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

function-call-argument-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

function-paren-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

generator-star-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

global-require deprecated

Categories:

โŒ

handle-callback-err deprecated

Categories:

โŒ

id-blacklist deprecated

Replaced by id-denylist

Categories:

โŒ

implicit-arrow-linebreak deprecated

Categories:

โŒ

๐Ÿ”ง Fix

indent deprecated

Categories:

โŒ

๐Ÿ”ง Fix

indent-legacy deprecated

Replaced by indent

Categories:

โŒ

๐Ÿ”ง Fix

jsx-quotes deprecated

Categories:

โŒ

๐Ÿ”ง Fix

key-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

keyword-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

linebreak-style deprecated

Categories:

โŒ

๐Ÿ”ง Fix

lines-around-comment deprecated

Categories:

โŒ

๐Ÿ”ง Fix

lines-between-class-members deprecated

Categories:

โŒ

๐Ÿ”ง Fix

max-len deprecated

Categories:

โŒ

max-statements-per-line deprecated

Categories:

โŒ

multiline-ternary deprecated

Categories:

โŒ

๐Ÿ”ง Fix

new-parens deprecated

Categories:

โŒ

๐Ÿ”ง Fix

newline-per-chained-call deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-buffer-constructor deprecated

Categories:

โŒ

no-catch-shadow deprecated

Replaced by no-shadow

Categories:

โŒ

no-confusing-arrow deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-extra-parens deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-extra-semi deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-floating-decimal deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-mixed-operators deprecated

Categories:

โŒ

no-mixed-requires deprecated

Categories:

โŒ

no-mixed-spaces-and-tabs deprecated

Categories:

โŒ

no-multi-spaces deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-multiple-empty-lines deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-native-reassign deprecated

Replaced by no-global-assign

Categories:

โŒ

no-negated-in-lhs deprecated

Replaced by no-unsafe-negation

Categories:

โŒ

no-new-object deprecated

Replaced by no-object-constructor

Categories:

โŒ

no-new-require deprecated

Categories:

โŒ

no-path-concat deprecated

Categories:

โŒ

no-process-env deprecated

Categories:

โŒ

no-process-exit deprecated

Categories:

โŒ

no-restricted-modules deprecated

Categories:

โŒ

no-return-await deprecated

Categories:

โŒ

๐Ÿ’ก Suggestions

no-spaced-func deprecated

Replaced by func-call-spacing

Categories:

โŒ

๐Ÿ”ง Fix

no-sync deprecated

Categories:

โŒ

no-tabs deprecated

Categories:

โŒ

no-trailing-spaces deprecated

Categories:

โŒ

๐Ÿ”ง Fix

no-whitespace-before-property deprecated

Categories:

โŒ

๐Ÿ”ง Fix

nonblock-statement-body-position deprecated

Categories:

โŒ

๐Ÿ”ง Fix

object-curly-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

object-curly-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

object-property-newline deprecated

Categories:

โŒ

๐Ÿ”ง Fix

one-var-declaration-per-line deprecated

Categories:

โŒ

๐Ÿ”ง Fix

operator-linebreak deprecated

Categories:

โŒ

๐Ÿ”ง Fix

padded-blocks deprecated

Categories:

โŒ

๐Ÿ”ง Fix

padding-line-between-statements deprecated

Categories:

โŒ

๐Ÿ”ง Fix

prefer-reflect deprecated

Categories:

โŒ

quote-props deprecated

Categories:

โŒ

๐Ÿ”ง Fix

quotes deprecated

Categories:

โŒ

๐Ÿ”ง Fix

require-jsdoc deprecated

Categories:

โŒ

rest-spread-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

semi deprecated

Categories:

โŒ

๐Ÿ”ง Fix

semi-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

semi-style deprecated

Categories:

โŒ

๐Ÿ”ง Fix

space-before-blocks deprecated

Categories:

โŒ

๐Ÿ”ง Fix

space-before-function-paren deprecated

Categories:

โŒ

๐Ÿ”ง Fix

space-in-parens deprecated

Categories:

โŒ

๐Ÿ”ง Fix

space-infix-ops deprecated

Categories:

โŒ

๐Ÿ”ง Fix

space-unary-ops deprecated

Categories:

โŒ

๐Ÿ”ง Fix

spaced-comment deprecated

Categories:

โŒ

๐Ÿ”ง Fix

switch-colon-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

template-curly-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

template-tag-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

valid-jsdoc deprecated

Categories:

โŒ

๐Ÿ”ง Fix

wrap-iife deprecated

Categories:

โŒ

๐Ÿ”ง Fix

wrap-regex deprecated

Categories:

โŒ

๐Ÿ”ง Fix

yield-star-spacing deprecated

Categories:

โŒ

๐Ÿ”ง Fix

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

no-empty-label removed

Replaced by no-labels

no-extra-strict removed

Replaced by strict

Change Language