Skip to content

Latest commit

 

History

History
262 lines (235 loc) · 22.6 KB

README.md

File metadata and controls

262 lines (235 loc) · 22.6 KB

Rules

Rules in ESLint are divided into several categories to help you better understand their value. All rules are disabled by default. ESLint recommends some rules to catch common problems, and you can use these recommended rules by including extends: "eslint:recommended" in your configuration file. The rules that will be enabled when you inherit from eslint:recommended are indicated below as "(recommended)". For more information on how to configure rules and use extends, please see the configuration documentation.

Some rules are fixable using the --fix command line flag. Those rules are marked as "(fixable)" below.

Possible Errors

The following rules point out areas where you might have made mistakes.

  • comma-dangle - disallow or enforce trailing commas (recommended)
  • no-cond-assign - disallow assignment in conditional expressions (recommended)
  • no-console - disallow use of console (recommended)
  • no-constant-condition - disallow use of constant expressions in conditions (recommended)
  • no-control-regex - disallow control characters in regular expressions (recommended)
  • no-debugger - disallow use of debugger (recommended)
  • no-dupe-args - disallow duplicate arguments in functions (recommended)
  • no-dupe-keys - disallow duplicate keys when creating object literals (recommended)
  • no-duplicate-case - disallow a duplicate case label. (recommended)
  • no-empty-character-class - disallow the use of empty character classes in regular expressions (recommended)
  • no-empty - disallow empty statements (recommended)
  • no-ex-assign - disallow assigning to the exception in a catch block (recommended)
  • no-extra-boolean-cast - disallow double-negation boolean casts in a boolean context (recommended)
  • no-extra-parens - disallow unnecessary parentheses
  • no-extra-semi - disallow unnecessary semicolons (recommended) (fixable)
  • no-func-assign - disallow overwriting functions written as function declarations (recommended)
  • no-inner-declarations - disallow function or variable declarations in nested blocks (recommended)
  • no-invalid-regexp - disallow invalid regular expression strings in the RegExp constructor (recommended)
  • no-irregular-whitespace - disallow irregular whitespace outside of strings and comments (recommended)
  • no-negated-in-lhs - disallow negation of the left operand of an in expression (recommended)
  • no-obj-calls - disallow the use of object properties of the global object (Math and JSON) as functions (recommended)
  • no-regex-spaces - disallow multiple spaces in a regular expression literal (recommended)
  • no-sparse-arrays - disallow sparse arrays (recommended)
  • no-unexpected-multiline - Avoid code that looks like two expressions but is actually one (recommended)
  • no-unreachable - disallow unreachable statements after a return, throw, continue, or break statement (recommended)
  • use-isnan - disallow comparisons with the value NaN (recommended)
  • valid-jsdoc - Ensure JSDoc comments are valid
  • valid-typeof - Ensure that the results of typeof are compared against a valid string (recommended)

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
  • array-callback-return - Enforces return statements in callbacks of array's methods
  • 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 in switch statements
  • dot-location - enforces consistent newlines before or after dots
  • dot-notation - encourages use of dot notation whenever possible
  • eqeqeq - require the use of === and !==
  • guard-for-in - make sure for-in loops have an if statement
  • no-alert - disallow the use of alert, confirm, and prompt
  • no-caller - disallow use of arguments.caller or arguments.callee
  • no-case-declarations - disallow lexical declarations in case clauses (recommended)
  • no-div-regex - disallow division operators explicitly at beginning of regular expression
  • no-else-return - disallow else after a return in an if
  • no-empty-label - disallow use of labels for anything other than loops and switches (recommended)
  • no-empty-pattern - disallow use of empty destructuring patterns (recommended)
  • 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 (recommended)
  • 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-implicit-globals - disallow var and named functions in global scope
  • 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-magic-numbers - disallow the use of magic numbers
  • no-multi-spaces - disallow use of multiple spaces (fixable)
  • 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, and Boolean
  • 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 (recommended)
  • 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 (recommended)
  • 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-unmodified-loop-condition - disallow unmodified conditions of loops
  • no-unused-expressions - disallow usage of expressions in statement position
  • no-useless-call - disallow unnecessary .call() and .apply()
  • no-useless-concat - disallow unnecessary concatenation of literals or template literals
  • no-void - disallow use of the void operator
  • no-warning-comments - disallow usage of configurable warning terms in comments - e.g. TODO or FIXME
  • 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 and strict mode directives.

  • strict - require effective use of strict mode 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 (recommended)
  • 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 (recommended)
  • no-undefined - disallow use of undefined variable
  • no-unused-vars - disallow declaration of variables that are not used in the code (recommended)
  • no-use-before-define - disallow use of variables before they are defined

Node.js and CommonJS

These rules are specific to JavaScript running on Node.js or using CommonJS in the browser.

Stylistic Issues

These rules are purely matters of style and are quite subjective.

ECMAScript 6

These rules are only relevant to ES6 environments.

Removed

These rules existed in a previous version of ESLint but have since been replaced by newer rules.