Rules
Rules in ESLint are divided into several categories to help you better understand their value. Though none are enabled by default, some are specifically recommended by ESLint and may be turned on using configuration.
Possible Errors
The following rules point out areas where you might have made mistakes.
- comma-dangle - disallow or enforce trailing commas
- no-cond-assign - disallow assignment in conditional expressions
- no-console - disallow use of
console
in the node environment - no-constant-condition - disallow use of constant expressions in conditions
- no-control-regex - disallow control characters in regular expressions
- no-debugger - disallow use of
debugger
- no-dupe-args - disallow duplicate arguments in functions
- no-dupe-keys - disallow duplicate keys when creating object literals
- no-duplicate-case - disallow a duplicate case label.
- no-empty-character-class - disallow the use of empty character classes in regular expressions
- no-empty - disallow empty statements
- no-ex-assign - disallow assigning to the exception in a
catch
block - no-extra-boolean-cast - disallow double-negation boolean casts in a boolean context
- no-extra-parens - disallow unnecessary parentheses
- no-extra-semi - disallow unnecessary semicolons
- no-func-assign - disallow overwriting functions written as function declarations
- no-inner-declarations - disallow function or variable declarations in nested blocks
- no-invalid-regexp - disallow invalid regular expression strings in the
RegExp
constructor - no-irregular-whitespace - disallow irregular whitespace outside of strings and comments
- no-negated-in-lhs - disallow negation of the left operand of an
in
expression - no-obj-calls - disallow the use of object properties of the global object (
Math
andJSON
) as functions - no-regex-spaces - disallow multiple spaces in a regular expression literal
- no-reserved-keys - disallow reserved words being used as object literal keys
- no-sparse-arrays - disallow sparse arrays
- no-unreachable - disallow unreachable statements after a return, throw, continue, or break statement
- use-isnan - disallow comparisons with the value
NaN
- valid-jsdoc - Ensure JSDoc comments are valid
- valid-typeof - Ensure that the results of typeof are compared against a valid string
- no-unexpected-multiline - Avoid code that looks like two expressions but is actually one
Best Practices
These are rules designed to prevent you from making mistakes. They either prescribe a better way of doing something or help you avoid footguns.
- accessor-pairs - Enforces getter/setter pairs in objects
- block-scoped-var - treat
var
statements as if they were block scoped - complexity - specify the maximum cyclomatic complexity allowed in a program
- consistent-return - require
return
statements to either always or never specify values - curly - specify curly brace conventions for all control statements
- default-case - require
default
case inswitch
statements - dot-notation - encourages use of dot notation whenever possible
- dot-location - enforces consistent newlines before or after dots
- eqeqeq - require the use of
===
and!==
- guard-for-in - make sure
for-in
loops have anif
statement - no-alert - disallow the use of
alert
,confirm
, andprompt
- no-caller - disallow use of
arguments.caller
orarguments.callee
- no-div-regex - disallow division operators explicitly at beginning of regular expression
- no-else-return - disallow
else
after areturn
in anif
- no-empty-label - disallow use of labels for anything other than loops and switches
- no-eq-null - disallow comparisons to null without a type-checking operator
- no-eval - disallow use of
eval()
- no-extend-native - disallow adding to native types
- no-extra-bind - disallow unnecessary function binding
- no-fallthrough - disallow fallthrough of
case
statements - no-floating-decimal - disallow the use of leading or trailing decimal points in numeric literals
- no-implicit-coercion - disallow the type conversions with shorter notations
- no-implied-eval - disallow use of
eval()
-like methods - no-invalid-this - disallow
this
keywords outside of classes or class-like objects - no-iterator - disallow usage of
__iterator__
property - no-labels - disallow use of labeled statements
- no-lone-blocks - disallow unnecessary nested blocks
- no-loop-func - disallow creation of functions within loops
- no-multi-spaces - disallow use of multiple spaces
- no-multi-str - disallow use of multiline strings
- no-native-reassign - disallow reassignments of native objects
- no-new-func - disallow use of new operator for
Function
object - no-new-wrappers - disallows creating new instances of
String
,Number
, andBoolean
- no-new - disallow use of the
new
operator when not part of an assignment or comparison - no-octal-escape - disallow use of octal escape sequences in string literals, such as
var foo = "Copyright \251";
- no-octal - disallow use of octal literals
- no-param-reassign - disallow reassignment of function parameters
- no-process-env - disallow use of
process.env
- no-proto - disallow usage of
__proto__
property - no-redeclare - disallow declaring the same variable more than once
- no-return-assign - disallow use of assignment in
return
statement - no-script-url - disallow use of
javascript:
urls. - no-self-compare - disallow comparisons where both sides are exactly the same
- no-sequences - disallow use of the comma operator
- no-throw-literal - restrict what can be thrown as an exception
- no-unused-expressions - disallow usage of expressions in statement position
- no-useless-call - disallow unnecessary
.call()
and.apply()
- no-void - disallow use of the
void
operator - no-warning-comments - disallow usage of configurable warning terms in comments - e.g.
TODO
orFIXME
- no-with - disallow use of the
with
statement - radix - require use of the second argument for
parseInt()
- vars-on-top - require declaration of all vars at the top of their containing scope
- wrap-iife - require immediate function invocation to be wrapped in parentheses
- yoda - require or disallow Yoda conditions
Strict Mode
These rules relate to using strict mode.
- strict - controls location of Use Strict Directives
Variables
These rules have to do with variable declarations.
- init-declarations - enforce or disallow variable initializations at definition
- no-catch-shadow - disallow the catch clause parameter name being the same as a variable in the outer scope
- no-delete-var - disallow deletion of variables
- no-label-var - disallow labels that share a name with a variable
- no-shadow-restricted-names - disallow shadowing of names such as
arguments
- no-shadow - disallow declaration of variables already declared in the outer scope
- no-undef-init - disallow use of undefined when initializing variables
- no-undef - disallow use of undeclared variables unless mentioned in a
/*global */
block - no-undefined - disallow use of
undefined
variable - no-unused-vars - disallow declaration of variables that are not used in the code
- no-use-before-define - disallow use of variables before they are defined
Node.js
These rules are specific to JavaScript running on Node.js.
- callback-return - enforce
return
after a callback - handle-callback-err - enforce error handling in callbacks
- no-mixed-requires - disallow mixing regular variable and require declarations
- no-new-require - disallow use of
new
operator with therequire
function - no-path-concat - disallow string concatenation with
__dirname
and__filename
- no-process-exit - disallow
process.exit()
- no-restricted-modules - restrict usage of specified node modules
- no-sync - disallow use of synchronous methods
Stylistic Issues
These rules are purely matters of style and are quite subjective.
- array-bracket-spacing - enforce spacing inside array brackets
- brace-style - enforce one true brace style
- camelcase - require camel case names
- comma-spacing - enforce spacing before and after comma
- comma-style - enforce one true comma style
- computed-property-spacing - require or disallow padding inside computed properties
- consistent-this - enforce consistent naming when capturing the current execution context
- eol-last - enforce newline at the end of file, with no multiple empty lines
- func-names - require function expressions to have a name
- func-style - enforce use of function declarations or expressions
- indent - specify tab or space width for your code
- key-spacing - enforce spacing between keys and values in object literal properties
- lines-around-comment - enforce empty lines around comments
- linebreak-style - disallow mixed ‘LF’ and ‘CRLF’ as linebreaks
- max-nested-callbacks - specify the maximum depth callbacks can be nested
- new-cap - require a capital letter for constructors
- new-parens - disallow the omission of parentheses when invoking a constructor with no arguments
- newline-after-var - require or disallow an empty newline after variable declarations
- no-array-constructor - disallow use of the
Array
constructor - no-continue - disallow use of the
continue
statement - no-inline-comments - disallow comments inline after code
- no-lonely-if - disallow
if
as the only statement in anelse
block - no-mixed-spaces-and-tabs - disallow mixed spaces and tabs for indentation
- no-multiple-empty-lines - disallow multiple empty lines
- no-nested-ternary - disallow nested ternary expressions
- no-new-object - disallow the use of the
Object
constructor - no-spaced-func - disallow space between function identifier and application
- no-ternary - disallow the use of 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 the use of
Boolean
literals in conditional expressions - object-curly-spacing - require or disallow padding inside curly braces
- one-var - require or disallow one variable declaration per function
- operator-assignment - require assignment operator shorthand where possible or prohibit it entirely
- operator-linebreak - enforce operators to be placed before or after line breaks
- padded-blocks - enforce padding within blocks
- quote-props - require quotes around object literal property names
- quotes - specify whether backticks, double or single quotes should be used
- semi-spacing - enforce spacing before and after semicolons
- semi - require or disallow use of semicolons instead of ASI
- sort-vars - sort variables within the same declaration block
- space-after-keywords - require a space after certain keywords
- space-before-blocks - require or disallow a space before blocks
- space-before-function-paren - require or disallow a space before function opening parenthesis
- space-in-parens - require or disallow spaces inside parentheses
- space-infix-ops - require spaces around operators
- space-return-throw-case - require a space after
return
,throw
, andcase
- space-unary-ops - require or disallow spaces before/after unary operators
- spaced-comment - require or disallow a space immediately following the
//
or/*
in a comment - wrap-regex - require regex literals to be wrapped in parentheses
ECMAScript 6
These rules are only relevant to ES6 environments.
- arrow-parens - require parens in arrow function arguments
- arrow-spacing - require space before/after arrow function’s arrow
- constructor-super - verify calls of
super()
in constructors - generator-star-spacing - enforce spacing around the
*
in generator functions - no-class-assign - disallow modifying variables of class declarations
- no-const-assign - disallow modifying variables that are declared using
const
- no-this-before-super - disallow use of
this
/super
before callingsuper()
in constructors. - no-var - require
let
orconst
instead ofvar
- object-shorthand - require method and property shorthand syntax for object literals
- prefer-const - suggest using
const
declaration for variables that are never modified after declared - prefer-spread - suggest using the spread operator instead of
.apply()
. - prefer-reflect - suggest using Reflect methods where applicable
- require-yield - disallow generator functions that do not have
yield
Legacy
The following rules are included for compatibility with JSHint and JSLint. While the names of the rules may not match up with the JSHint/JSLint counterpart, the functionality is the same.
- max-depth - specify the maximum depth that blocks can be nested
- max-len - specify the maximum length of a line in your program
- max-params - limits the number of parameters that can be used in the function declaration.
- max-statements - specify the maximum number of statement allowed in a function
- no-bitwise - disallow use of bitwise operators
- no-plusplus - disallow use of unary operators,
++
and--
Removed
These rules existed in a previous version of ESLint but have since been replaced by newer rules.
- generator-star - enforce the position of the
*
in generator functions (replaced by generator-star-spacing) - global-strict - require or disallow the
"use strict"
pragma in the global scope (replaced by strict) - no-comma-dangle - disallow trailing commas in object literals (replaced by comma-dangle)
- no-empty-class - disallow the use of empty character classes in regular expressions (replaced by no-empty-character-class)
- no-extra-strict - disallow unnecessary use of
"use strict";
when already in strict mode (replaced by strict) - no-space-before-semi - disallow space before semicolon (replaced by semi-spacing)
- no-wrap-func - disallow wrapping of non-IIFE statements in parens (replaced by no-extra-parens)
- space-after-function-name - require a space after function names (replaced by space-before-function-paren)
- space-before-function-parentheses - require or disallow space before function parentheses (replaced by space-before-function-paren)
- space-in-brackets - require or disallow spaces inside brackets (replaced by object-curly-spacing and array-bracket-spacing)
- space-unary-word-ops - require or disallow spaces before/after unary operators (replaced by space-unary-ops)
- spaced-line-comment - require or disallow a space immediately following the
//
in a line comment (replaced by spaced-comment)