Skip to content

Latest commit

 

History

History
195 lines (170 loc) · 15.7 KB

README.md

File metadata and controls

195 lines (170 loc) · 15.7 KB

Rules

Rules in ESLint are divided into several categories to help you better understand their value. Additionally, not all rules are enabled by default. Those that are not enabled by default are marked as being off.

Possible Errors

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

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.

  • block-scoped-var - treat var statements as if they were block scoped (off by default)
  • complexity - specify the maximum cyclomatic complexity allowed in a program (off by default)
  • 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 (off by default)
  • 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 (off by default)
  • no-alert - disallow the use of alert, confirm, and prompt
  • no-caller - disallow use of arguments.caller or arguments.callee
  • no-div-regex - disallow division operators explicitly at beginning of regular expression (off by default)
  • no-else-return - disallow else after a return in an if (off by default)
  • no-empty-label - disallow use of labels for anything other then loops and switches
  • no-eq-null - disallow comparisons to null without a type-checking operator (off by default)
  • 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 (off by default)
  • no-implied-eval - disallow use of eval()-like methods
  • 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 - disallow use of new operator when not part of the assignment or comparison
  • no-new-func - disallow use of new operator for Function object
  • no-new-wrappers - disallows creating new instances of String,Number, and Boolean
  • no-octal - disallow use of octal literals
  • no-octal-escape - disallow use of octal escape sequences in string literals, such as var foo = "Copyright \251";
  • no-process-env - disallow use of process.env (off by default)
  • no-proto - disallow usage of __proto__ property
  • no-redeclare - disallow declaring the same variable more then 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 (off by default)
  • no-sequences - disallow use of comma operator
  • no-throw-literal - restrict what can be thrown as an exception (off by default)
  • no-unused-expressions - disallow usage of expressions in statement position
  • no-void - disallow use of void operator (off by default)
  • no-warning-comments - disallow usage of configurable warning terms in comments - e.g. TODO or FIXME (off by default)
  • no-with - disallow use of the with statement
  • radix - require use of the second argument for parseInt() (off by default)
  • vars-on-top - requires to declare all vars on top of their containing scope (off by default)
  • wrap-iife - require immediate function invocation to be wrapped in parentheses (off by default)
  • yoda - require or disallow Yoda conditions

Strict Mode

These rules relate to using strict mode.

  • global-strict - (deprecated) require or disallow the "use strict" pragma in the global scope (off by default in the node environment)
  • no-extra-strict - (deprecated) disallow unnecessary use of "use strict"; when already in strict mode
  • strict - controls location of Use Strict Directives

Variables

These rules have to do with variable declarations.

  • no-catch-shadow - disallow the catch clause parameter name being the same as a variable in the outer scope (off by default in the node environment)
  • no-delete-var - disallow deletion of variables
  • no-label-var - disallow labels that share a name with a variable
  • no-shadow - disallow declaration of variables already declared in the outer scope
  • no-shadow-restricted-names - disallow shadowing of names such as arguments
  • no-undef - disallow use of undeclared variables unless mentioned in a /*global */ block
  • no-undef-init - disallow use of undefined when initializing variables
  • no-undefined - disallow use of undefined variable (off by default)
  • 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.

  • handle-callback-err - enforces error handling in callbacks (off by default) (on by default in the node environment)
  • no-mixed-requires - disallow mixing regular variable and require declarations (off by default) (on by default in the node environment)
  • no-new-require - disallow use of new operator with the require function (off by default) (on by default in the node environment)
  • no-path-concat - disallow string concatenation with __dirname and __filename (off by default) (on by default in the node environment)
  • no-process-exit - disallow process.exit() (on by default in the node environment)
  • no-restricted-modules - restrict usage of specified node modules (off by default)
  • no-sync - disallow use of synchronous methods (off by default)

Stylistic Issues

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

  • indent - this option sets a specific tab width for your code (off by default)
  • brace-style - enforce one true brace style (off by default)
  • camelcase - require camel case names
  • comma-spacing - enforce spacing before and after comma
  • comma-style - enforce one true comma style (off by default)
  • consistent-this - enforces consistent naming when capturing the current execution context (off by default)
  • eol-last - enforce newline at the end of file, with no multiple empty lines
  • func-names - require function expressions to have a name (off by default)
  • func-style - enforces use of function declarations or expressions (off by default)
  • key-spacing - enforces spacing between keys and values in object literal properties
  • max-nested-callbacks - specify the maximum depth callbacks can be nested (off by default)
  • new-cap - require a capital letter for constructors
  • new-parens - disallow the omission of parentheses when invoking a constructor with no arguments
  • no-array-constructor - disallow use of the Array constructor
  • no-inline-comments - disallow comments inline after code (off by default)
  • no-lonely-if - disallow if as the only statement in an else block (off by default)
  • no-mixed-spaces-and-tabs - disallow mixed spaces and tabs for indentation
  • no-multiple-empty-lines - disallow multiple empty lines (off by default)
  • no-nested-ternary - disallow nested ternary expressions (off by default)
  • no-new-object - disallow use of the Object constructor
  • no-space-before-semi - (deprecated) disallow space before semicolon (off by default)
  • no-spaced-func - disallow space between function identifier and application
  • no-ternary - disallow the use of ternary operators (off by default)
  • no-trailing-spaces - disallow trailing whitespace at the end of lines
  • no-underscore-dangle - disallow dangling underscores in identifiers
  • no-wrap-func - disallow wrapping of non-IIFE statements in parens
  • one-var - allow just one var statement per function (off by default)
  • operator-assignment - require assignment operator shorthand where possible or prohibit it entirely (off by default)
  • padded-blocks - enforce padding within blocks (off by default)
  • quote-props - require quotes around object literal property names (off by default)
  • quotes - specify whether double or single quotes should be used
  • semi - require or disallow use of semicolons instead of ASI
  • semi-spacing - enforce spacing before and after semicolons
  • sort-vars - sort variables within the same declaration block (off by default)
  • space-after-function-name - (deprecated) require a space after function names (off by default)
  • space-after-keywords - require a space after certain keywords (off by default)
  • space-before-blocks - require or disallow space before blocks (off by default)
  • space-before-function-parentheses - require or disallow space before function parentheses (off by default)
  • space-in-brackets - require or disallow spaces inside brackets (off by default)
  • space-in-parens - require or disallow spaces inside parentheses (off by default)
  • space-infix-ops - require spaces around operators
  • space-return-throw-case - require a space after return, throw, and case
  • space-unary-ops - Require or disallow spaces before/after unary operators (words on by default, nonwords off by default)
  • spaced-line-comment - require or disallow a space immediately following the // in a line comment (off by default)
  • wrap-regex - require regex literals to be wrapped in parentheses (off by default)

ECMAScript 6

These rules are only relevant to ES6 environments and are off by default.

  • no-class - avoid use of class (off by default)
  • no-var - require let or const instead of var (off by default)
  • generator-star - (deprecated) enforce the position of the * in generator functions (off by default)
  • generator-star-spacing - enforce the spacing around the * in generator functions (off by default)

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 (off by default)
  • max-len - specify the maximum length of a line in your program (off by default)
  • max-params - limits the number of parameters that can be used in the function declaration. (off by default)
  • max-statements - specify the maximum number of statement allowed in a function (off by default)
  • no-bitwise - disallow use of bitwise operators (off by default)
  • no-plusplus - disallow use of unary operators, ++ and -- (off by default)