ESLint config for 5Minds projects
- install with npm install --save-dev eslint-config-5minds
- create a .eslintrc config with
Have fun ;-)
Possible errors
1.1 no-cond-assign: disallow assignment operators in conditional expressions.
// goodif x === 0
// badif x = 0
1.2 no-console: disallow the use of console
.
// badconsole;
1.3 no-constant-condition: disallow constant expressions in conditions.
// badif false
1.4 no-control-regex: disallow control characters in regular expressions.
// badconst pattern = /\x1f/;
1.5 no-debugger: disallow the use of debugger
.
// baddebugger;
1.6 no-dupe-args: disallow duplicate arguments in function
definitions.
// bad { console;}
1.7 no-dupe-keys: disallow duplicate keys in object literals.
// badconst foo bar: 1 qux: 2 bar: 3
1.8 no-duplicate-case: disallow duplicate case labels.
// bad
1.9 no-empty: disallow empty block statements.
// bad { }
1.10 no-empty-character-class: disallow empty character classes in regular expressions.
// bad'abcdefg'; // null
1.11 no-ex-assign: disallow reassigning exceptions in catch
clauses.
// badtry ; catch error error = 'You cannot parse letters.'; throw error;
1.12 no-extra-boolean-cast: disallow unnecessary boolean casts.
// bad { if Booleannum return -1 * num; else throw 'missing input'; }
// good { if num return -1 * num; else throw 'missing input'; }
1.13 no-extra-semi: disallow unnecessary semicolons.
// bad;
1.14 no-func-assign: disallow reassigning function
declarations.
// bad { }foo = 'bar';
1.15 no-inner-declarations: disallow variable or function
declarations in nested blocks.
const Foo = { // good -> This is a function within a function { } // good -> This is an instance method(same as declared with ES6-Class) Fooprototype { return this === otherFoo; }; return Foo;}; // good -> this is a global function { return ;}
// bad -> function in nested blockif foo { }
1.16 no-invalid-regexp: disallow invalid regular expression strings in RegExp
constructors.
// good'bar';
// bad'foo'
1.17 no-irregular-whitespace: disallow irregular whitespace outside of strings and comments. Various whitespace characters can be inputted by programmers by mistake for example from copying or keyboard shortcuts. Pressing Alt + Space on OS X adds in a non breaking space character for example.
1.18 no-obj-calls: disallow calling global object properties as functions.
// badMath;
1.19 no-prototype-builtins: disallow calling some Object.prototype
methods directly on objects.
// goodfoo;
// badObjectprototypehasOwnProperty;
1.20 no-regex-spaces: disallow multiple spaces in regular expressions.
// good' '; // better' ';
// bad' ';
1.21 no-sparse-arrays: disallow sparse arrays.
// goodconst colors = "red" "blue" ;colorslength === 2; // true
// badconst colors = "red" "blue";
1.22 no-unexpected-multiline: disallow confusing multiline expressions.
// goodconst hello = 'world';1 2 3;
// badconst hello = 'world'1 2 3;
1.23 no-unreachable: disallow unreachable code after return
, throw
, continue
, and break
statements.
// good { console;return true;}
// bad { return true; console;}
1.24 no-unsafe-finally: disallow control flow statements in finally
blocks.
// bad -> We expect this function to throw an error, then return { try throw "Try"; // error is thrown but suspended until finally block ends finally return 3; // 3 is returned before the error is thrown, which we did not expect };
1.25 no-unsafe-negation: disallow negating the left operand of relational operators.
// goodif !key in object // key is not in object
// badif !key in object // equivalent to (!key) in object
1.26 use-isnan: require calls to isNaN()
when checking for NaN
.
// goodif
// badif foo == NaN
1.27 valid-typeof: enforce comparing typeof
expressions against valid strings.
// goodif typeof foo === 'string'
// badif typeof foo === 'strnng'
Best practices
2.1 array-callback-return: enforce return
statements in callbacks of array methods.
// goodlist; // goodlist;
// badlist;
2.2 block-scoped-var: enforce the use of variables within the scope they are defined.
// good { var build; if true build = true; console;}
// bad { if true var build = true; console;}
2.3 consistent-return: require return
statements to either always or never specify values.
// good { if condition return true; else return false; }
// bad { if condition return true; else return; }
2.4 curly: enforce consistent brace style for all control statements.
// goodif foo ;
// badif foo ;else ;
2.5 default-case: require default
cases in switch
statements.
// good
// bad
2.6 dot-location: enforce consistent newlines before property dots.
// gooddocumentdocumentElement
// baddocumentdocumentElement
2.7 dot-notation: enforce dot notation whenever possible.
// goodobjectfoo = true;objectfoo = true;object'foo bar' = true;
// badobject'foo' = true;
2.8 eqeqeq: require the use of ===
and !==
except for null-checks.
// goodif foo == null if bar === 0
// badif foo == 0
2.9 guard-for-in: require for-in
loops to include an if
statement.
// goodfor key in foo if ObjectprototypehasOwnProperty ; // betterObject;
// badfor key in foo ;
2.10 no-alert: disallow the use of alert
, confirm
, and prompt
.
// bad;
2.11 no-caller: disallow the use of arguments.caller
or arguments.callee
.
// good { return !n > 1 ? 1 : * n;} 1 2 3 4 5;
// bad1 2 3 4 5;
2.12 no-case-declarations: disallow lexical declarations in case clauses.
// good
// bad
2.13 no-else-return: disallow else
blocks after return
statements in if
statements.
// good { if x return y; var t = "foo";}
// bad { if x return y; else var t = "foo"; }
2.14 no-empty-function: disallow empty functions.
// bad { }
2.15 no-empty-pattern: disallow empty destructuring patterns.
// good -> sets default valuevar a= {} = foo;
// bad -> does not create a varvar a: {} = foo;
2.16 no-eval: disallow the use of eval()
.
// good
// bad;
2.17 no-extend-native: disallow extending native types.
// badObjectprototypefoo = 'bar';
2.18 no-extra-bind: disallow unnecessary calls to .bind()
.
// goodvar boundGetName = { return thisname;}; console;
// bad -> uselessvar boundGetName = { return "ESLint";}; console;
2.19 no-extra-label: disallow unnecessary labels.
// badA: while a break A;
2.20 no-fallthrough: disallow fallthrough of case
statements.
// good
// bad
2.21 no-floating-decimal: disallow leading or trailing decimal points in numeric literals.
// goodvar num = 05;var num = 20;var num = -07;
// badvar num = 5;var num = 2;var num = -7;
2.22 no-global-assign: disallow assignments to native objects or read-only global variables.
// badundefined = null;
2.23 no-implied-eval: disallow the use of eval()
-like methods.
// good;
// bad;
2.24 no-iterator: disallow the use of the __iterator__
property.
// badFooprototype { return this;};
2.25 no-labels: disallow labeled statements.
// badA: while a break A;
2.26 no-lone-blocks: disallow unnecessary nested blocks.
// good { ;}
// bad { ; }
2.27 no-loop-func: disallow function
declarations and expressions inside loop statements.
// gooddo { return i; }; ; while i;
2.28 no-multi-spaces: disallow multiple spaces.
2.29 no-multi-str: disallow multiline strings.
// goodconst blindText = `Lorem ipsumet dolor`;
// goodconst blindText = 'Lorem ipsum et dolor';
// badconst blindText = 'Lorem ipsum \et dolor';
2.30 no-new: disallow new
operators outside of assignments or comparisons.
// goodvar thing = ; ;
// bad;
2.31 no-new-func: disallow new
operators with the Function
object.
// badvar x = "a" "b" "return a + b";
2.32 no-new-wrappers: disallow new
operators with the String
, Number
, and Boolean
objects.
// goodconst stringObject = 'Hello world';
// badconst stringObject = 'Hello world';
2.33 no-octal: disallow octal literals.
// badconst num = 071;
2.34 no-octal-escape: disallow octal escape sequences in string literals.
// goodconst foo = "Copyright \u00A9"; // unicode
// badconst foo = "Copyright \251"; // octal
2.35 no-param-reassign: disallow reassigning function
parameters.
// bad { bar++;}
2.36 no-proto: disallow the use of the __proto__
property.
// goodconst a = Object;
// badconst a = obj__proto__;
2.37 no-redeclare: disallow variable redeclaration.
// goodlet a = 3;a = 10;
// badlet a = 3;let a = 10;
2.38 no-return-assign: disallow assignment operators in return
statements.
// bad { return foo = bar + 2;}
2.39 no-script-url: disallow javascript:
urls.
// badlocationhref = "javascript:void(0)";
2.40 no-self-assign: disallow assignments where both sides are exactly the same.
// goodfoo = bar;
// badfoo = foo;
2.41 no-self-compare: disallow comparisons where both sides are exactly the same.
// badif x === x
2.42 no-sequences: disallow comma operators.
// good -> init and update of for is an exceptionfor i = 0 j = 10; i < j; i++ j--;
// bad -> use && insteadwhile val = val < 42;
2.43 no-throw-literal: disallow throwing literals as exceptions.
// goodthrow 'error';
// badthrow 'error';
2.44 no-unused-expressions: disallow unused expressions.
// gooda ? : ;
// bada ? b : 0;
2.45 no-unused-labels: disallow unused labels.
// goodA: if break A; ;
// badA: var foo = 0;
2.46 no-useless-call: disallow unnecessary calls to .call()
and .apply()
.
// goodfoo;
// badfoo;
2.47 no-useless-concat: disallow unnecessary concatenation of literals or template literals.
// goodconst a = a + '1';
// badconst a = `some` + `string`;
2.48 no-useless-escape: disallow unnecessary escape characters.
// badlet foo = "hol\a"; // > foo = "hola"
2.49 no-useless-return: disallow redundant return statements.
// good { ;}
// bad { ; return;}
2.50 no-void: disallow void
operators.
// badvar foo = void ;
2.51 no-with: disallow with
statements.
// badwith point r = Math; // is r a member of point?
2.52 radix: enforce the consistent use of the radix argument when using parseInt()
.
// good;
// bad;
2.53 vars-on-top: require var
declarations to be placed at the top of their containing scope.
// good { var first; var second; if true first = true; }
// bad { var first; if true first = true; var second;}
2.54 wrap-iife: require parentheses around immediate function
invocations.
// goodvar x = { return y: 1 ;};
// badvar { return y: 1 ;};var x = { return y: 1 ;};
2.55 yoda: disallow “Yoda” conditions.
// goodif color === 'red' // ...
// badif 'red' === color // ...
Strict
Variables
4.1 no-delete-var: disallow deleting variables.
// badvar x;delete x;
4.2 no-label-var: disallow labels that share a name with a variable.
// badvar x = foo; {x: for ;; break x; }
4.3 no-shadow: disallow variable declarations from shadowing variables declared in the outer scope.
// badvar a = 3; { var a = 10;}
4.4 no-shadow-restricted-names: disallow identifiers from shadowing restricted names.
// bad{}
4.5 no-undef: disallow the use of undeclared variables unless mentioned in /*global */
comments.
// goodconst b = 10;
// badb = 10;
4.6 no-undef-init: disallow initializing variables to undefined
.
// goodconst undef = undefined;
// badlet undef = undefined;
4.7 no-unused-vars: disallow unused variables.
// goodvar y = 10;;
// badvar y = 10;y = 2;
4.8 no-use-before-define: disallow the use of variables before they are defined.
// bad;var y = 10;
Node.Js and CommonJS
5.1 global-require: require require()
calls to be placed at top-level module scope.
// goodvar fs = ;
// bad { if condition var fs = ; }
5.2 no-new-require: disallow new
operators with calls to require
.
// goodvar AppHeader = ;var appHeader = ;
// badvar appHeader = 'app-header';
5.3 no-path-concat: disallow string concatenation with __dirname
and __filename
.
// goodvar fullPath = path;
// badvar fullPath = __dirname + "/foo.js";
Stylistic Issues
6.1 array-bracket-spacing: enforce no spacing inside array brackets.
// goodvar arr = 'foo' 'bar';var x y = z;
// badvar arr = 'foo' 'bar' ;var x y = z;
6.2 block-spacing: enforce consistent spacing inside single-line blocks.
// good { return true; }if foo bar = 0;
// bad {return true;}if foo bar = 0;
6.3 brace-style: enforce consistent brace style for blocks(1TBS).
// goodif foo ; else ;
// badif foo ;else ;
6.4 camelcase: enforce camelcase naming convention.
// goodconst camelCase = 'good';
// badconst snake_case = 'bad';
6.5 comma-dangle: require or disallow trailing commas.
// goodconst foo = bar: 'baz' qux: 'quux';
// badconst foo = bar: 'baz' qux: 'quux';
6.6 comma-spacing: enforce consistent spacing before and after commas.
// goodconst arr = 1 2;
// badconst arr = 1 2;
6.7 comma-style: enforce consistent comma style.
// good { return 'a': 1 'b:': 2 ;}
// bad { return 'a': 1 'b:': 2 ;}
6.8 computed-property-spacing: enforce consistent spacing inside computed property brackets.
// goodobjkey
// badobj key
6.9 eol-last: require or disallow newline at the end of files.
6.10 func-name-matching: require function names to match the name of the variable or property to which they are assigned.
// goodvar {};
// badvar {};
6.11 func-names: require or disallow named function
expressions.
// goodarr;
// badarr;
6.12 indent: enforce consistent indentation(2 spaces).
6.13 key-spacing: enforce consistent spacing between keys and values in object literal properties.
// goodvar obj = "foo": 42 ;
// badvar obj = "foo" : 42 ;
6.14 keyword-spacing: enforce consistent spacing before and after keywords.
// goodif foo //... else if bar //... else //...
// badif foo //...else if bar //... else //...
6.15 linebreak-style: enforce consistent linebreak style(unix -> LF instead of CRLF)
6.16 max-len: enforce a maximum line length of 100 characters.
6.17 new-cap: require constructor names to begin with a capital letter.
// goodconst c = ;
// badconst c = ;
6.18 new-parens: require parentheses when invoking a constructor with no arguments.
// goodconst c = ;
// badconst c = ;
6.19 newline-per-chained-call: require a newline after each call in a method chain.
// good;
// bad;
6.20 no-array-constructor: disallow Array
constructors.
// bad0 1 2
6.21 no-continue: disallow continue
statements.
// badcontinue;
6.22 no-lonely-if: disallow if
statements as the only statement in else
blocks.
// goodif foo // ... else if bar // ... }
// badif foo // ... else if bar // ...
6.23 no-mixed-operators: disallow mixed binary operators.
// goodlet i = 2 + 2 * 2;
// badlet i = 2 + 2 * 2;
6.24 no-mixed-spaces-and-tabs: disallow mixed spaces and tabs for indentation.
6.25 no-multi-assign: disallow use of chained assignment expressions.
// badvar a = b = c = 5;
6.26 no-multiple-empty-lines: disallow multiple empty lines.
// good; ;;
// bad; ;
6.27 no-nested-ternary: disallow nested ternary expressions.
// badvar foo = bar ? baz : qux === quxx ? bing : bam;
6.28 no-new-object: disallow Object
constructors.
// goodvar myObject = {};
// badvar myObject = ;
6.29 no-restricted-syntax: disallow specified syntax(e.g. debugger, with, labels)
6.30 no-underscore-dangle: disallow dangling underscores in identifiers.
// badvar _foo;
6.31 no-unneeded-ternary: disallow ternary operators when simpler alternatives exist.
// goodconst a = Booleancondition;
// badconst a = condition ? true : false;
6.32 no-whitespace-before-property: disallow whitespace before properties.
// goodfoobarbazquz
// badfoo bar baz quz
6.33 object-curly-spacing: enforce consistent spacing inside braces.
// goodvar obj = 'foo': 'bar';
// badvar obj = 'foo': 'bar' ;
6.34 object-property-newline: enforce placing object properties on separate lines.
// goodvar obj = foo: "foo" bar: "bar" baz: "baz";
// badvar obj = foo: "foo" bar: "bar" baz: "baz";
6.35 one-var: enforce variables to be declared separately in functions.
// goodvar bar;var baz;
// badvar bar baz;
6.36 one-var-declaration-per-line: require or disallow newlines around variable declarations.
// goodconst a = 0 b = 0;
// badconst a = 0 b = 0;
6.37 operator-assignment: require or disallow assignment operator shorthand where possible.
// goodx += y;
// badx = x + y;
6.38 padded-blocks: disallow padding within blocks.
// goodif a ;
// badif a ;
6.39 quote-props: require quotes around object literal property names if needed, otherwise forbid them.
// goodvar object1 = "a-b": 0 "0x0": 0 "1e2": 0 foo: 0;
// badvar object = "a": 0 "0": 0 "true": 0 "null": 0;
6.40 quotes: enforce the consistent use of single quotes. Template-Strings are still allowed(if they contain a JS-Expression).
// goodconst hw = 'Hello world';// goodconst hw2 = ` world`;
// badconst hw = "Hello world";// badconst hw2 = `Hello world`;
6.41 semi: require semicolons instead of ASI(automatic semicolon insertion).
// goodvar name = "ESLint";
// badvar name = "ESLint"
6.42 semi-spacing: enforce consistent spacing before and after semicolons.
// goodvar foo;
// badvar foo ;
6.43 space-before-blocks: enforce consistent spacing before blocks.
// goodif a ;
// badif a ;
6.44 space-before-function-paren: disallow spacing before function
definition opening parenthesis(except for anonymous functions).
// good { return { }};
// bad { // ...};
6.45 space-in-parens: enforce consistent spacing inside parentheses.
// good;
// bad;;;
6.46 space-infix-ops: require spacing around infix operators.
// gooda + b
// bada+b
6.47 space-unary-ops: enforce consistent spacing before or after unary operators.
// goodtypeof foo;
// badtypeoffoo;
6.48 spaced-comment: enforce consistent spacing after the //
or /*
in a comment.
// good// This is a comment with a whitespace at the beginning
// bad//This is a comment with no whitespace at the beginning
6.49 unicode-bom: require or disallow Unicode byte order mark (BOM).
The Unicode Byte Order Mark (BOM) is used to specify whether code units are big endian or little endian. That is, whether the most significant or least significant bytes come first. UTF-8 does not require a BOM because byte ordering does not matter when characters are a single byte. Since UTF-8 is the dominant encoding of the web, we make "never" the default option.
ECMAScript 6
7.1 arrow-body-style: require braces around arrow function bodies.
// goodconst foo = { return 0;};
// badconst foo = 0;
7.2 arrow-spacing: enforce consistent spacing before and after the arrow in arrow functions.
// good {};
// bad {};{};{};
7.3 constructor-super: require super()
calls in constructors.
// good { }// good { super; }
// bad { super; }// bad { }
7.4 generator-star-spacing: enforce consistent spacing behind *
operators in generator functions.
// good {}
// bad {}
7.5 no-class-assign: disallow reassigning class members.
// goodlet A = A = 0;
// bad A = 0;
7.6 no-confusing-arrow: disallow arrow functions where they could be confused with comparisons.
// goodvar 1 ? 2 : 3;
// badvar { return 1 ? 2 : 3; };
7.7 no-const-assign: disallow reassigning const
variables.
// badconst a = 0;a = 1;
7.8 no-dupe-class-members: disallow duplicate class members.
// bad { } { }
7.9 no-duplicate-imports: disallow duplicate module imports.
// good;
// bad;;
7.10 no-new-symbol: disallow new
operators with the Symbol
object.
// badvar foo = 'foo';
7.11 no-this-before-super: disallow this
/super
before calling super()
in constructors.
// good { super; thisa = 0; }
// bad { thisa = 0; super; }
7.12 no-useless-computed-key: disallow unnecessary computed property keys in object literals.
// goodvar a = x: 0 ;
// badvar a = 'x': 0 ;
7.13 no-useless-constructor: disallow unnecessary constructors.
// good { ; }
// bad { }
7.14 no-useless-rename: disallow renaming import, export, and destructured assignments to the same name.
// good;
// bad;
7.15 no-var: require let
or const
instead of var
.
// goodlet foo;const bar;
// badvar qux;
7.16 object-shorthand: require or disallow method and property shorthand syntax for object literals.
// goodvar foo = {} "qux": qux;
// badvar foo = "bar-baz" {};
7.17 prefer-arrow-callback: require arrow functions as callbacks.
// goodapp;
// badapp;
7.18 prefer-const: require const
declarations for variables that are never reassigned after declared.
// goodconst pi = 314;
// badlet pi = 314
7.19 prefer-numeric-literals: disallow parseInt()
in favor of binary, octal, and hexadecimal literals.
// bad === 503;
7.20 prefer-rest-params: require rest parameters instead of arguments
.
// good { console;}
// bad { console;}
7.21 prefer-spread: require spread operators instead of .apply()
.
// good;
// badfoo;
7.22 prefer-template: require template literals instead of string concatenation.
// goodvar str = `Hello !`;
// badvar str = 'Hello, ' + name + '!';
7.23 require-yield: require generator functions to contain yield
.
// good { 5; return 10;}
// bad { return 10;}
7.24 rest-spread-spacing: enforce spacing between rest and spread operators and their expressions.
// good
// bad
7.25 template-curly-spacing: disallow spacing around embedded expressions of template strings.
// good`hello, !`;
// bad`hello, !`;
7.26 yield-star-spacing: require spacing after the *
in yield*
expressions.
// good { ;}