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
function
definitions - 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
catch
clauses - 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
function
declarations - no-inner-declarations: disallow
function
orvar
declarations in nested blocks - no-invalid-regexp: disallow invalid regular expression strings in
RegExp
constructors - no-irregular-whitespace: disallow irregular whitespace outside of strings and comments
- no-negated-in-lhs: disallow negating the left operand in
in
expressions - no-obj-calls: disallow calling global object properties as functions
- no-prototype-builtins: Disallow use of
Object.prototypes
builtins 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
, andbreak
statements - no-unsafe-finally: disallow control flow statements in
finally
blocks - use-isnan: require calls to
isNaN()
when checking forNaN
- valid-jsdoc: enforce valid JSDoc comments
- valid-typeof: enforce comparing
typeof
expressions 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
return
statements 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
return
statements to either always or never specify values - curly: enforce consistent brace style for all control statements
- default-case: require
default
cases inswitch
statements - 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-in
loops to include anif
statement - no-alert: disallow the use of
alert
,confirm
, andprompt
- no-caller: disallow the use of
arguments.caller
orarguments.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
else
blocks afterreturn
statements inif
statements - no-empty-function: disallow empty functions
- no-empty-pattern: disallow empty destructuring patterns
- 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-label: disallow unnecessary labels
- no-fallthrough: disallow fallthrough of
case
statements - no-floating-decimal: disallow leading or trailing decimal points in numeric literals
- no-implicit-coercion: disallow shorthand type conversions
- no-implicit-globals: disallow
var
and namedfunction
declarations in the global scope - no-implied-eval: disallow the use of
eval()
-like methods - no-invalid-this: disallow
this
keywords 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
function
declarations 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
new
operators outside of assignments or comparisons - no-new-func: disallow
new
operators with theFunction
object - no-new-wrappers: disallow
new
operators with theString
,Number
, andBoolean
objects - no-octal: disallow octal literals
- no-octal-escape: disallow octal escape sequences in string literals
- no-param-reassign: disallow reassigning
function
parameters - no-proto: disallow the use of the
__proto__
property - no-redeclare: disallow
var
redeclaration - no-return-assign: disallow assignment operators in
return
statements - 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
void
operators - no-warning-comments: disallow specified warning terms in comments
- no-with: disallow
with
statements - radix: enforce the consistent use of the radix argument when using
parseInt()
- vars-on-top: require
var
declarations be placed at the top of their containing scope - wrap-iife: require parentheses around immediate
function
invocations - 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
var
declarations - no-catch-shadow: disallow
catch
clause 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
var
declarations 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
undefined
as 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
return
statements 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
require
calls to be mixed with regularvar
declarations - no-new-require: disallow
new
operators with calls torequire
- no-path-concat: disallow string concatenation with
__dirname
and__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
function
expressions - func-style: enforce the consistent use of either
function
declarations 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
function
definitions - max-statements: enforce a maximum number of statements allowed in
function
blocks - max-statements-per-line: enforce a maximum number of statements allowed per line
- new-cap: require constructor
function
names 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
var
declarations - newline-before-return: require an empty line before
return
statements - newline-per-chained-call: require a newline after each call in a method chain
- no-array-constructor: disallow
Array
constructors - no-bitwise: disallow bitwise operators
- no-continue: disallow
continue
statements - no-inline-comments: disallow inline comments after code
- no-lonely-if: disallow
if
statements as the only statement inelse
blocks - 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
Object
constructors - no-plusplus: disallow the unary operators
++
and--
- no-restricted-syntax: disallow specified syntax
- no-spaced-func: disallow spacing between
function
identifiers 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
var
declarations - 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
function
definition 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
const
variables - no-dupe-class-members: disallow duplicate class members
- no-duplicate-imports: disallow duplicate module imports
- no-new-symbol: disallow
new
operators with theSymbol
object - no-restricted-imports: disallow specified modules when loaded by
import
- no-this-before-super: disallow
this
/super
before 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
let
orconst
instead 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
const
declarations for variables that are never reassigned after declared - prefer-reflect: require
Reflect
methods 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: