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:
- comma-dangle: require or disallow trailing commas
- no-cond-assign: disallow assignment operators in conditional expressions
- no-console: disallow the use of
console - no-constant-condition: disallow constant expressions in conditions
- no-control-regex: disallow control characters in regular expressions
- no-debugger: disallow the use of
debugger - no-dupe-args: disallow duplicate arguments in
functiondefinitions - no-dupe-keys: disallow duplicate keys in object literals
- no-duplicate-case: disallow duplicate case labels
- no-empty: disallow empty block statements
- no-empty-character-class: disallow empty character classes in regular expressions
- no-ex-assign: disallow reassigning exceptions in
catchclauses - no-extra-boolean-cast: disallow unnecessary boolean casts
- no-extra-parens: disallow unnecessary parentheses
- no-extra-semi: disallow unnecessary semicolons
- no-func-assign: disallow reassigning
functiondeclarations - no-inner-declarations: disallow
functionorvardeclarations in nested blocks - no-invalid-regexp: disallow invalid regular expression strings in
RegExpconstructors - no-irregular-whitespace: disallow irregular whitespace outside of strings and comments
- no-negated-in-lhs: disallow negating the left operand in
inexpressions - no-obj-calls: disallow calling global object properties as functions
- no-prototype-builtins: Disallow use of
Object.prototypesbuiltins directly - no-regex-spaces: disallow multiple spaces in regular expression literals
- no-sparse-arrays: disallow sparse arrays
- no-unexpected-multiline: disallow confusing multiline expressions
- no-unreachable: disallow unreachable code after
return,throw,continue, andbreakstatements - no-unsafe-finally: disallow control flow statements in
finallyblocks - use-isnan: require calls to
isNaN()when checking forNaN - valid-jsdoc: enforce valid JSDoc comments
- valid-typeof: enforce comparing
typeofexpressions against valid strings
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
- array-callback-return: enforce
returnstatements in callbacks of array methods - block-scoped-var: enforce the use of variables within the scope they are defined
- complexity: enforce a maximum cyclomatic complexity allowed in a program
- consistent-return: require
returnstatements to either always or never specify values - curly: enforce consistent brace style for all control statements
- default-case: require
defaultcases inswitchstatements - dot-location: enforce consistent newlines before and after dots
- dot-notation: enforce dot notation whenever possible
- eqeqeq: require the use of
===and!== - guard-for-in: require
for-inloops to include anifstatement - no-alert: disallow the use of
alert,confirm, andprompt - no-caller: disallow the use of
arguments.callerorarguments.callee - no-case-declarations: disallow lexical declarations in case clauses
- no-div-regex: disallow division operators explicitly at the beginning of regular expressions
- no-else-return: disallow
elseblocks afterreturnstatements inifstatements - no-empty-function: disallow empty functions
- no-empty-pattern: disallow empty destructuring patterns
- no-eq-null: disallow
nullcomparisons 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-label: disallow unnecessary labels
- no-fallthrough: disallow fallthrough of
casestatements - no-floating-decimal: disallow leading or trailing decimal points in numeric literals
- no-implicit-coercion: disallow shorthand type conversions
- no-implicit-globals: disallow
varand namedfunctiondeclarations in the global scope - no-implied-eval: disallow the use of
eval()-like methods - no-invalid-this: disallow
thiskeywords outside of classes or class-like objects - no-iterator: disallow the use of the
__iterator__property - no-labels: disallow labeled statements
- no-lone-blocks: disallow unnecessary nested blocks
- no-loop-func: disallow
functiondeclarations and expressions inside loop statements - no-magic-numbers: disallow magic numbers
- no-multi-spaces: disallow multiple spaces
- no-multi-str: disallow multiline strings
- no-native-reassign: disallow reassigning native objects
- no-new: disallow
newoperators outside of assignments or comparisons - no-new-func: disallow
newoperators with theFunctionobject - no-new-wrappers: disallow
newoperators with theString,Number, andBooleanobjects - no-octal: disallow octal literals
- no-octal-escape: disallow octal escape sequences in string literals
- no-param-reassign: disallow reassigning
functionparameters - no-proto: disallow the use of the
__proto__property - no-redeclare: disallow
varredeclaration - no-return-assign: disallow assignment operators in
returnstatements - no-script-url: disallow
javascript:urls - 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-sequences: disallow comma operators
- no-throw-literal: disallow throwing literals as exceptions
- no-unmodified-loop-condition: disallow unmodified loop conditions
- no-unused-expressions: disallow unused expressions
- no-unused-labels: disallow unused labels
- no-useless-call: disallow unnecessary calls to
.call()and.apply() - no-useless-concat: disallow unnecessary concatenation of literals or template literals
- no-useless-escape: disallow unnecessary escape characters
- no-void: disallow
voidoperators - no-warning-comments: disallow specified warning terms in comments
- no-with: disallow
withstatements - radix: enforce the consistent use of the radix argument when using
parseInt() - vars-on-top: require
vardeclarations be placed at the top of their containing scope - wrap-iife: require parentheses around immediate
functioninvocations - yoda: require or disallow “Yoda” conditions
Strict Mode
These rules relate to strict mode directives:
- strict: require or disallow strict mode directives
Variables
These rules relate to variable declarations:
- init-declarations: require or disallow initialization in
vardeclarations - no-catch-shadow: disallow
catchclause parameters from shadowing variables in the outer scope - no-delete-var: disallow deleting variables
- no-label-var: disallow labels that share a name with a variable
- no-restricted-globals: disallow specified global variables
- no-shadow: disallow
vardeclarations from shadowing variables in the outer scope - no-shadow-restricted-names: disallow identifiers from shadowing restricted names
- no-undef: disallow the use of undeclared variables unless mentioned in
/*global */comments - no-undef-init: disallow initializing variables to
undefined - no-undefined: disallow the use of
undefinedas an identifier - no-unused-vars: disallow unused variables
- no-use-before-define: disallow the use of variables before they are defined
Node.js and CommonJS
These rules relate to code running in Node.js, or in browsers with CommonJS:
- callback-return: require
returnstatements after callbacks - global-require: require
require()calls to be placed at top-level module scope - handle-callback-err: require error handling in callbacks
- no-mixed-requires: disallow
requirecalls to be mixed with regularvardeclarations - no-new-require: disallow
newoperators with calls torequire - no-path-concat: disallow string concatenation with
__dirnameand__filename - no-process-env: disallow the use of
process.env - no-process-exit: disallow the use of
process.exit() - no-restricted-modules: disallow specified modules when loaded by
require - no-sync: disallow synchronous methods
Stylistic Issues
These rules relate to style guidelines, and are therefore quite subjective:
- array-bracket-spacing: enforce consistent spacing inside array brackets
- block-spacing: enforce consistent spacing inside single-line blocks
- brace-style: enforce consistent brace style for blocks
- camelcase: enforce camelcase naming convention
- 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
- consistent-this: enforce consistent naming when capturing the current execution context
- eol-last: enforce at least one newline at the end of files
- func-names: require or disallow named
functionexpressions - func-style: enforce the consistent use of either
functiondeclarations or expressions - id-blacklist: disallow specified identifiers
- id-length: enforce minimum and maximum identifier lengths
- id-match: require identifiers to match a specified regular expression
- 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
- linebreak-style: enforce consistent linebreak style
- lines-around-comment: require empty lines around comments
- max-depth: enforce a maximum depth that blocks can be nested
- max-len: enforce a maximum line length
- max-lines: enforce a maximum file length
- max-nested-callbacks: enforce a maximum depth that callbacks can be nested
- max-params: enforce a maximum number of parameters in
functiondefinitions - max-statements: enforce a maximum number of statements allowed in
functionblocks - max-statements-per-line: enforce a maximum number of statements allowed per line
- new-cap: require constructor
functionnames to begin with a capital letter - new-parens: require parentheses when invoking a constructor with no arguments
- newline-after-var: require or disallow an empty line after
vardeclarations - newline-before-return: require an empty line before
returnstatements - newline-per-chained-call: require a newline after each call in a method chain
- no-array-constructor: disallow
Arrayconstructors - no-bitwise: disallow bitwise operators
- no-continue: disallow
continuestatements - no-inline-comments: disallow inline comments after code
- no-lonely-if: disallow
ifstatements as the only statement inelseblocks - no-mixed-operators: disallow mixes of different operators
- no-mixed-spaces-and-tabs: disallow mixed spaces and tabs for indentation
- no-multiple-empty-lines: disallow multiple empty lines
- no-negated-condition: disallow negated conditions
- no-nested-ternary: disallow nested ternary expressions
- no-new-object: disallow
Objectconstructors - no-plusplus: disallow the unary operators
++and-- - no-restricted-syntax: disallow specified syntax
- no-spaced-func: disallow spacing between
functionidentifiers and their applications - no-ternary: disallow ternary operators
- no-trailing-spaces: disallow trailing whitespace at the end of lines
- no-underscore-dangle: disallow dangling underscores in identifiers
- no-unneeded-ternary: disallow ternary operators when simpler alternatives exist
- no-whitespace-before-property: disallow whitespace before properties
- object-curly-newline: enforce consistent line breaks inside braces
- object-curly-spacing: enforce consistent spacing inside braces
- object-property-newline: enforce placing object properties on separate lines
- one-var: enforce variables to be declared either together or separately in functions
- one-var-declaration-per-line: require or disallow newlines around
vardeclarations - operator-assignment: require or disallow assignment operator shorthand where possible
- operator-linebreak: enforce consistent linebreak style for operators
- padded-blocks: require or disallow padding within blocks
- quote-props: require quotes around object literal property names
- quotes: enforce the consistent use of either backticks, double, or single quotes
- require-jsdoc: require JSDoc comments
- semi: require or disallow semicolons instead of ASI
- semi-spacing: enforce consistent spacing before and after semicolons
- sort-vars: require variables within the same declaration block to be sorted
- space-before-blocks: enforce consistent spacing before blocks
- space-before-function-paren: enforce consistent spacing before
functiondefinition opening parenthesis - space-in-parens: enforce consistent spacing inside parentheses
- space-infix-ops: require spacing around operators
- space-unary-ops: enforce consistent spacing before or after unary operators
- spaced-comment: enforce consistent spacing after the
//or/*in a comment - unicode-bom: require or disallow the Unicode BOM
- wrap-regex: require parenthesis around regex literals
ECMAScript 6
These rules relate to ES6, also known as ES2015:
- arrow-body-style: require braces around arrow function bodies
- arrow-parens: require parentheses around arrow function arguments
- arrow-spacing: enforce consistent spacing before and after the arrow in arrow functions
- constructor-super: require
super()calls in constructors - generator-star-spacing: enforce consistent spacing around
*operators in generator functions - no-class-assign: disallow reassigning class members
- no-confusing-arrow: disallow arrow functions where they could be confused with comparisons
- no-const-assign: disallow reassigning
constvariables - no-dupe-class-members: disallow duplicate class members
- no-duplicate-imports: disallow duplicate module imports
- no-new-symbol: disallow
newoperators with theSymbolobject - no-restricted-imports: disallow specified modules when loaded by
import - no-this-before-super: disallow
this/superbefore callingsuper()in constructors - no-useless-computed-key: disallow unnecessary computed property keys in object literals
- no-useless-constructor: disallow unnecessary constructors
- no-useless-rename: disallow renaming import, export, and destructured assignments to the same name
- no-var: require
letorconstinstead ofvar - object-shorthand: require or disallow method and property shorthand syntax for object literals
- prefer-arrow-callback: require arrow functions as callbacks
- prefer-const: require
constdeclarations for variables that are never reassigned after declared - prefer-reflect: require
Reflectmethods where applicable - 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
- require-yield: require generator functions to contain
yield - rest-spread-spacing: enforce spacing between rest and spread operators and their expressions
- sort-imports: enforce sorted import declarations within modules
- template-curly-spacing: require or disallow spacing around embedded expressions of template strings
- yield-star-spacing: require or disallow spacing around the
*inyield*expressions
Removed
These rules from older versions of ESLint have been replaced by newer rules: