Rules
Rules in ESLint are grouped by type to help you understand their purpose. Each rule has emojis denoting:
if theΒ "extends": "eslint:recommended"
Β property in aΒ configuration fileΒ enables the rule
if some problems reported by the rule are automatically fixable by theΒ --fix
Β command lineΒ option
if some problems reported by the 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 | |||
β | constructor-super | require `super()` calls in constructors | ||
β | for-direction | enforce "for" loop update clause moving the counter in the right direction. | ||
β | getter-return | enforce `return` statements in getters | ||
β | no-async-promise-executor | disallow using an async function as a Promise executor | ||
no-await-in-loop | disallow `await` inside of loops | |||
β | no-class-assign | disallow reassigning class members | ||
β | no-compare-neg-zero | disallow comparing against -0 | ||
β | no-cond-assign | disallow assignment operators in conditional expressions | ||
β | no-const-assign | disallow reassigning `const` variables | ||
no-constant-binary-expression | disallow expressions where the operation doesn't affect the value | |||
β | no-constant-condition | disallow constant expressions in conditions | ||
no-constructor-return | disallow returning value from constructor | |||
β | no-control-regex | disallow control characters in regular expressions | ||
β | no-debugger | disallow the use of `debugger` | ||
β | no-dupe-args | disallow duplicate arguments in `function` definitions | ||
β | no-dupe-class-members | disallow duplicate class members | ||
β | no-dupe-else-if | disallow duplicate conditions in if-else-if chains | ||
β | no-dupe-keys | disallow duplicate keys in object literals | ||
β | no-duplicate-case | disallow duplicate case labels | ||
no-duplicate-imports | disallow duplicate module imports | |||
β | no-empty-character-class | disallow empty character classes in regular expressions | ||
β | no-empty-pattern | disallow empty destructuring patterns | ||
β | no-ex-assign | disallow reassigning exceptions in `catch` clauses | ||
β | no-fallthrough | disallow fallthrough of `case` statements | ||
β | no-func-assign | disallow reassigning `function` declarations | ||
β | no-import-assign | disallow assigning to imported bindings | ||
β | no-inner-declarations | disallow variable or `function` declarations in nested blocks | ||
β | no-invalid-regexp | disallow invalid regular expression strings in `RegExp` constructors | ||
β | no-irregular-whitespace | disallow irregular whitespace | ||
β | no-loss-of-precision | disallow literal numbers that lose precision | ||
β | π‘ | no-misleading-character-class | disallow characters which are made with multiple code points in character class syntax | |
β | no-new-symbol | disallow `new` operators with the `Symbol` object | ||
β | no-obj-calls | disallow calling global object properties as functions | ||
no-promise-executor-return | disallow returning values from Promise executor functions | |||
β | no-prototype-builtins | disallow calling some `Object.prototype` methods directly on objects | ||
β | no-self-assign | disallow assignments where both sides are exactly the same | ||
no-self-compare | disallow comparisons where both sides are exactly the same | |||
β | no-setter-return | disallow returning values from setters | ||
β | no-sparse-arrays | disallow sparse arrays | ||
no-template-curly-in-string | disallow template literal placeholder syntax in regular strings | |||
β | no-this-before-super | disallow `this`/`super` before calling `super()` in constructors | ||
β | no-undef | disallow the use of undeclared variables unless mentioned in `/*global */` comments | ||
β | no-unexpected-multiline | disallow confusing multiline expressions | ||
no-unmodified-loop-condition | disallow unmodified loop conditions | |||
β | no-unreachable | disallow unreachable code after `return`, `throw`, `continue`, and `break` statements | ||
no-unreachable-loop | disallow loops with a body that allows only one iteration | |||
β | no-unsafe-finally | disallow control flow statements in `finally` blocks | ||
β | π‘ | no-unsafe-negation | disallow negating the left operand of relational operators | |
β | no-unsafe-optional-chaining | disallow use of optional chaining in contexts where the `undefined` value is not allowed | ||
no-unused-private-class-members | disallow unused private class members | |||
β | no-unused-vars | disallow unused variables | ||
no-use-before-define | disallow the use of variables before they are defined | |||
β | no-useless-backreference | disallow useless backreferences in regular expressions | ||
require-atomic-updates | disallow assignments that can lead to race conditions due to usage of `await` or `yield` | |||
β | use-isnan | require calls to `isNaN()` when checking for `NaN` | ||
β | π‘ | valid-typeof | enforce comparing `typeof` expressions against valid strings |
Suggestions
These rules suggest alternate ways of doing things:
accessor-pairs | enforce getter and setter pairs in objects and classes | |||
π§ | arrow-body-style | require braces around arrow function bodies | ||
block-scoped-var | enforce the use of variables within the scope they are defined | |||
camelcase | enforce camelcase naming convention | |||
π§ | capitalized-comments | enforce or disallow capitalization of the first letter of a comment | ||
class-methods-use-this | enforce that class methods utilize `this` | |||
complexity | enforce a maximum cyclomatic complexity allowed in a program | |||
consistent-return | require `return` statements to either always or never specify values | |||
consistent-this | enforce consistent naming when capturing the current execution context | |||
π§ | curly | enforce consistent brace style for all control statements | ||
default-case | require `default` cases in `switch` statements | |||
default-case-last | enforce default clauses in switch statements to be last | |||
default-param-last | enforce default parameters to be last | |||
π§ | dot-notation | enforce dot notation whenever possible | ||
π§ | eqeqeq | require the use of `===` and `!==` | ||
func-name-matching | require function names to match the name of the variable or property to which they are assigned | |||
func-names | require or disallow named `function` expressions | |||
func-style | enforce the consistent use of either `function` declarations or expressions | |||
grouped-accessor-pairs | require grouped accessor pairs in object literals and classes | |||
guard-for-in | require `for-in` loops to include an `if` statement | |||
id-denylist | disallow specified identifiers | |||
id-length | enforce minimum and maximum identifier lengths | |||
id-match | require identifiers to match a specified regular expression | |||
init-declarations | require or disallow initialization in variable declarations | |||
max-classes-per-file | enforce a maximum number of classes per file | |||
max-depth | enforce a maximum depth that blocks can be nested | |||
max-lines | enforce a maximum number of lines per file | |||
max-lines-per-function | enforce a maximum number of lines of code in a function | |||
max-nested-callbacks | enforce a maximum depth that callbacks can be nested | |||
max-params | enforce a maximum number of parameters in function definitions | |||
max-statements | enforce a maximum number of statements allowed in function blocks | |||
π§ | multiline-comment-style | enforce a particular style for multiline comments | ||
new-cap | require constructor names to begin with a capital letter | |||
no-alert | disallow the use of `alert`, `confirm`, and `prompt` | |||
no-array-constructor | disallow `Array` constructors | |||
no-bitwise | disallow bitwise operators | |||
no-caller | disallow the use of `arguments.caller` or `arguments.callee` | |||
β | no-case-declarations | disallow lexical declarations in case clauses | ||
π§ | no-confusing-arrow | disallow arrow functions where they could be confused with comparisons | ||
no-console | disallow the use of `console` | |||
no-continue | disallow `continue` statements | |||
β | no-delete-var | disallow deleting variables | ||
π§ | no-div-regex | disallow division operators explicitly at the beginning of regular expressions | ||
π§ | no-else-return | disallow `else` blocks after `return` statements in `if` statements | ||
β | no-empty | disallow empty block statements | ||
no-empty-function | disallow empty functions | |||
no-eq-null | disallow `null` comparisons without type-checking operators | |||
no-eval | disallow the use of `eval()` | |||
no-extend-native | disallow extending native types | |||
π§ | no-extra-bind | disallow unnecessary calls to `.bind()` | ||
β | π§ | no-extra-boolean-cast | disallow unnecessary boolean casts | |
π§ | no-extra-label | disallow unnecessary labels | ||
β | π§ | no-extra-semi | disallow unnecessary semicolons | |
π§ | no-floating-decimal | disallow leading or trailing decimal points in numeric literals | ||
β | no-global-assign | disallow assignments to native objects or read-only global variables | ||
π§ | no-implicit-coercion | disallow shorthand type conversions | ||
no-implicit-globals | disallow declarations in the global scope | |||
no-implied-eval | disallow the use of `eval()`-like methods | |||
no-inline-comments | disallow inline comments after code | |||
no-invalid-this | disallow use of `this` in contexts where the value of `this` is `undefined` | |||
no-iterator | disallow the use of the `__iterator__` property | |||
no-label-var | disallow labels that share a name with a variable | |||
no-labels | disallow labeled statements | |||
no-lone-blocks | disallow unnecessary nested blocks | |||
π§ | no-lonely-if | disallow `if` statements as the only statement in `else` blocks | ||
no-loop-func | disallow function declarations that contain unsafe references inside loop statements | |||
no-magic-numbers | disallow magic numbers | |||
no-mixed-operators | disallow mixed binary operators | |||
no-multi-assign | disallow use of chained assignment expressions | |||
no-multi-str | disallow multiline strings | |||
no-negated-condition | disallow negated conditions | |||
no-nested-ternary | disallow nested ternary expressions | |||
no-new | disallow `new` operators outside of assignments or comparisons | |||
no-new-func | disallow `new` operators with the `Function` object | |||
no-new-object | disallow `Object` constructors | |||
no-new-wrappers | disallow `new` operators with the `String`, `Number`, and `Boolean` objects | |||
β | π‘ | no-nonoctal-decimal-escape | disallow `\8` and `\9` escape sequences in string literals | |
β | no-octal | disallow octal literals | ||
no-octal-escape | disallow octal escape sequences in string literals | |||
no-param-reassign | disallow reassigning `function` parameters | |||
no-plusplus | disallow the unary operators `++` and `--` | |||
no-proto | disallow the use of the `__proto__` property | |||
β | no-redeclare | disallow variable redeclaration | ||
β | π§ | no-regex-spaces | disallow multiple spaces in regular expressions | |
no-restricted-exports | disallow specified names in exports | |||
no-restricted-globals | disallow specified global variables | |||
no-restricted-imports | disallow specified modules when loaded by `import` | |||
no-restricted-properties | disallow certain properties on certain objects | |||
no-restricted-syntax | disallow specified syntax | |||
no-return-assign | disallow assignment operators in `return` statements | |||
no-return-await | disallow unnecessary `return await` | |||
no-script-url | disallow `javascript:` urls | |||
no-sequences | disallow comma operators | |||
no-shadow | disallow variable declarations from shadowing variables declared in the outer scope | |||
β | no-shadow-restricted-names | disallow identifiers from shadowing restricted names | ||
no-ternary | disallow ternary operators | |||
no-throw-literal | disallow throwing literals as exceptions | |||
π§ | no-undef-init | disallow initializing variables to `undefined` | ||
no-undefined | disallow the use of `undefined` as an identifier | |||
no-underscore-dangle | disallow dangling underscores in identifiers | |||
π§ | no-unneeded-ternary | disallow ternary operators when simpler alternatives exist | ||
no-unused-expressions | disallow unused expressions | |||
β | π§ | no-unused-labels | disallow unused labels | |
no-useless-call | disallow unnecessary calls to `.call()` and `.apply()` | |||
β | no-useless-catch | disallow unnecessary `catch` clauses | ||
π§ | no-useless-computed-key | disallow unnecessary computed property keys in objects and classes | ||
no-useless-concat | disallow unnecessary concatenation of literals or template literals | |||
no-useless-constructor | disallow unnecessary constructors | |||
β | π‘ | no-useless-escape | disallow unnecessary escape characters | |
π§ | no-useless-rename | disallow renaming import, export, and destructured assignments to the same name | ||
π§ | no-useless-return | disallow redundant return statements | ||
π§ | no-var | require `let` or `const` instead of `var` | ||
no-void | disallow `void` operators | |||
no-warning-comments | disallow specified warning terms in comments | |||
β | no-with | disallow `with` statements | ||
π§ | object-shorthand | require or disallow method and property shorthand syntax for object literals | ||
π§ | one-var | enforce variables to be declared either together or separately in functions | ||
π§ | one-var-declaration-per-line | require or disallow newlines around variable declarations | ||
π§ | operator-assignment | require or disallow assignment operator shorthand where possible | ||
π§ | prefer-arrow-callback | require using arrow functions for callbacks | ||
π§ | prefer-const | require `const` declarations for variables that are never reassigned after declared | ||
π§ | prefer-destructuring | require destructuring from arrays and/or objects | ||
π§ | prefer-exponentiation-operator | disallow the use of `Math.pow` in favor of the `**` operator | ||
prefer-named-capture-group | enforce using named capture group in regular expression | |||
π§ | prefer-numeric-literals | disallow `parseInt()` and `Number.parseInt()` in favor of binary, octal, and hexadecimal literals | ||
π§ | prefer-object-has-own | disallow use of `Object.prototype.hasOwnProperty.call()` and prefer use of `Object.hasOwn()` | ||
π§ | prefer-object-spread | disallow using Object.assign with an object literal as the first argument and prefer the use of object spread instead. | ||
prefer-promise-reject-errors | require using Error objects as Promise rejection reasons | |||
π‘ | prefer-regex-literals | disallow use of the `RegExp` constructor in favor of regular expression literals | ||
prefer-rest-params | require rest parameters instead of `arguments` | |||
prefer-spread | require spread operators instead of `.apply()` | |||
π§ | prefer-template | require template literals instead of string concatenation | ||
π§ | quote-props | require quotes around object literal property names | ||
π‘ | radix | enforce the consistent use of the radix argument when using `parseInt()` | ||
require-await | disallow async functions which have no `await` expression | |||
require-unicode-regexp | enforce the use of `u` flag on RegExp | |||
β | require-yield | require generator functions to contain `yield` | ||
π§ | sort-imports | enforce sorted import declarations within modules | ||
sort-keys | require object keys to be sorted | |||
π§ | sort-vars | require variables within the same declaration block to be sorted | ||
π§ | spaced-comment | enforce consistent spacing after the `//` or `/*` in a comment | ||
π§ | strict | require or disallow strict mode directives | ||
symbol-description | require symbol descriptions | |||
vars-on-top | require `var` declarations be placed at the top of their containing scope | |||
π§ | yoda | require or disallow "Yoda" conditions |
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 | ||
π§ | array-bracket-spacing | enforce consistent spacing inside array brackets | ||
π§ | array-element-newline | enforce line breaks after each array element | ||
π§ | arrow-parens | require parentheses around arrow function arguments | ||
π§ | arrow-spacing | enforce consistent spacing before and after the arrow in arrow functions | ||
π§ | block-spacing | disallow or enforce spaces inside of blocks after opening block and before closing block | ||
π§ | brace-style | enforce consistent brace style for blocks | ||
π§ | comma-dangle | require or disallow trailing commas | ||
π§ | comma-spacing | enforce consistent spacing before and after commas | ||
π§ | comma-style | enforce consistent comma style | ||
π§ | computed-property-spacing | enforce consistent spacing inside computed property brackets | ||
π§ | dot-location | enforce consistent newlines before and after dots | ||
π§ | eol-last | require or disallow newline at the end of files | ||
π§ | func-call-spacing | require or disallow spacing between function identifiers and their invocations | ||
π§ | function-call-argument-newline | enforce line breaks between arguments of a function call | ||
π§ | function-paren-newline | enforce consistent line breaks inside function parentheses | ||
π§ | generator-star-spacing | enforce consistent spacing around `*` operators in generator functions | ||
π§ | implicit-arrow-linebreak | enforce the location of arrow function bodies | ||
π§ | indent | enforce consistent indentation | ||
π§ | jsx-quotes | enforce the consistent use of either double or single quotes in JSX attributes | ||
π§ | key-spacing | enforce consistent spacing between keys and values in object literal properties | ||
π§ | keyword-spacing | enforce consistent spacing before and after keywords | ||
line-comment-position | enforce position of line comments | |||
π§ | linebreak-style | enforce consistent linebreak style | ||
π§ | lines-around-comment | require empty lines around comments | ||
π§ | lines-between-class-members | require or disallow an empty line between class members | ||
max-len | enforce a maximum line length | |||
max-statements-per-line | enforce a maximum number of statements allowed per line | |||
π§ | multiline-ternary | enforce newlines between operands of ternary expressions | ||
π§ | new-parens | enforce or disallow parentheses when invoking a constructor with no arguments | ||
π§ | newline-per-chained-call | require a newline after each call in a method chain | ||
π§ | no-extra-parens | disallow unnecessary parentheses | ||
β | no-mixed-spaces-and-tabs | disallow mixed spaces and tabs for indentation | ||
π§ | no-multi-spaces | disallow multiple spaces | ||
π§ | no-multiple-empty-lines | disallow multiple empty lines | ||
no-tabs | disallow all tabs | |||
π§ | no-trailing-spaces | disallow trailing whitespace at the end of lines | ||
π§ | no-whitespace-before-property | disallow whitespace before properties | ||
π§ | nonblock-statement-body-position | enforce the location of single-line statements | ||
π§ | object-curly-newline | enforce consistent line breaks after opening and before closing braces | ||
π§ | object-curly-spacing | enforce consistent spacing inside braces | ||
π§ | object-property-newline | enforce placing object properties on separate lines | ||
π§ | operator-linebreak | enforce consistent linebreak style for operators | ||
π§ | padded-blocks | require or disallow padding within blocks | ||
π§ | padding-line-between-statements | require or disallow padding lines between statements | ||
π§ | quotes | enforce the consistent use of either backticks, double, or single quotes | ||
π§ | rest-spread-spacing | enforce spacing between rest and spread operators and their expressions | ||
π§ | semi | require or disallow semicolons instead of ASI | ||
π§ | semi-spacing | enforce consistent spacing before and after semicolons | ||
π§ | semi-style | enforce location of semicolons | ||
π§ | space-before-blocks | enforce consistent spacing before blocks | ||
π§ | space-before-function-paren | enforce consistent spacing before `function` definition opening parenthesis | ||
π§ | space-in-parens | enforce consistent spacing inside parentheses | ||
π§ | space-infix-ops | require spacing around infix operators | ||
π§ | space-unary-ops | enforce consistent spacing before or after unary operators | ||
π§ | switch-colon-spacing | enforce spacing around colons of switch statements | ||
π§ | template-curly-spacing | require or disallow spacing around embedded expressions of template strings | ||
π§ | template-tag-spacing | require or disallow spacing between template tags and their literals | ||
π§ | unicode-bom | require or disallow Unicode byte order mark (BOM) | ||
π§ | wrap-iife | require parentheses around immediate `function` invocations | ||
π§ | wrap-regex | require parenthesis around regex literals | ||
π§ | yield-star-spacing | require 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: