Skip to content

Latest commit

 

History

History
261 lines (234 loc) · 22.4 KB

README.md

File metadata and controls

261 lines (234 loc) · 22.4 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
  • 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.

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.