File routes.js
has 329 lines of code (exceeds 250 allowed). Consider refactoring. Open
import jwtHelper, { verifyJwt } from './jwt-helper'
import passport from 'koa-passport'
import validate from 'parameter'
import db from 'src/server/db'
import * as AuthActions from 'shared/actions/AuthActions'
Missing space after *. Open
.get('/api/v1/logout', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
This generator function does not have 'yield'. Open
.post('/auth/locale', function *(next) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.get('/auth/facebook', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/auth/facebook', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/api/v1/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/rss', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/sitemap/:key', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Expected property shorthand. Open
ctx.body = { token: token }
- Read upRead up
- Exclude checks
Require Object Literal Shorthand Syntax (object-shorthand)
EcmaScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.
Here are a few common examples using the ES5 syntax:
// properties
var foo = {
x: x,
y: y,
z: z,
};
// methods
var foo = {
a: function() {},
b: function() {}
};
Now here are ES6 equivalents:
/*eslint-env es6*/
// properties
var foo = {x, y, z};
// methods
var foo = {
a() {},
b() {}
};
Rule Details
This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.
Each of the following properties would warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w: function() {},
x: function *() {},
[y]: function() {},
z: z
};
In that case the expected syntax would have been:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w() {},
*x() {},
[y]() {},
z
};
This rule does not flag arrow functions inside of object literals. The following will not warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
x: (y) => y
};
Options
The rule takes an option which specifies when it should be applied. It can be set to one of the following values:
-
"always"
(default) expects that the shorthand will be used whenever possible. -
"methods"
ensures the method shorthand is used (also applies to generators). -
"properties"
ensures the property shorthand is used (where the key and variable name match). -
"never"
ensures that no property or method shorthand is used in any object literal. -
"consistent"
ensures that either all shorthand or all longform will be used in an object literal. -
"consistent-as-needed"
ensures that either all shorthand or all longform will be used in an object literal, but ensures all shorthand whenever possible.
You can set the option in configuration like this:
{
"object-shorthand": ["error", "always"]
}
Additionally, the rule takes an optional object configuration:
-
"avoidQuotes": true
indicates that longform syntax is preferred whenever the object key is a string literal (default:false
). Note that this option can only be enabled when the string option is set to"always"
,"methods"
, or"properties"
. -
"ignoreConstructors": true
can be used to prevent the rule from reporting errors for constructor functions. (By default, the rule treats constructors the same way as other functions.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
. -
"avoidExplicitReturnArrows": true
indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule allows either of these.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
.
avoidQuotes
{
"object-shorthand": ["error", "always", { "avoidQuotes": true }]
}
Example of incorrect code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz"() {}
};
Example of correct code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz": function() {},
"qux": qux
};
ignoreConstructors
{
"object-shorthand": ["error", "always", { "ignoreConstructors": true }]
}
Example of correct code for this rule with the "always", { "ignoreConstructors": true }
option:
/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
/*eslint-env es6*/
var foo = {
ConstructorFunction: function() {}
};
avoidExplicitReturnArrows
{
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }]
}
Example of incorrect code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo: (bar, baz) => {
return bar + baz;
},
qux: (foobar) => {
return foobar * 2;
}
};
Example of correct code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo(bar, baz) {
return bar + baz;
},
qux: foobar => foobar * 2
};
Example of incorrect code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a,
b: "foo",
};
Examples of correct code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: "foo"
};
var bar = {
a,
b,
};
Example of incorrect code with the "consistent-as-needed"
option, which is very similar to "consistent"
:
/*eslint object-shorthand: [2, "consistent-as-needed"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: b,
};
When Not To Use It
Anyone not yet in an ES6 environment would not want to apply this rule. Others may find the terseness of the shorthand syntax harder to read and may not want to encourage it with this rule.
Further Reading
Object initializer - MDN Source: http://eslint.org/docs/rules/
Missing space after *. Open
.post('/auth/locale', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.get('/auth/google/callback', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
This generator function does not have 'yield'. Open
}, function*(err, profile, failed) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
This generator function does not have 'yield'. Open
}, function*(err, profile, failed) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Unexpected string concatenation. Open
ctx.redirect('/sync/token?token=' + token)
- Read upRead up
- Exclude checks
Suggest using template literals instead of string concatenation. (prefer-template)
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = "Hello, " + name + "!";
/*eslint-env es6*/
var str = `Hello, ${name}!`;
Rule Details
This rule is aimed to flag usage of +
operators with strings.
Examples
Examples of incorrect code for this rule:
/*eslint prefer-template: "error"*/
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Examples of correct code for this rule:
/*eslint prefer-template: "error"*/
/*eslint-env es6*/
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
When Not To Use It
This rule should not be used in ES3/5 environments.
In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
Related Rules
- [no-useless-concat](no-useless-concat.md)
- [quotes](quotes.md) Source: http://eslint.org/docs/rules/
Missing space after *. Open
.get('/auth/google', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.post('/auth/token/verify', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.get('/auth/logout', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
}, function *(err, profile) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Expected property shorthand. Open
ctx.body = { token: token }
- Read upRead up
- Exclude checks
Require Object Literal Shorthand Syntax (object-shorthand)
EcmaScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.
Here are a few common examples using the ES5 syntax:
// properties
var foo = {
x: x,
y: y,
z: z,
};
// methods
var foo = {
a: function() {},
b: function() {}
};
Now here are ES6 equivalents:
/*eslint-env es6*/
// properties
var foo = {x, y, z};
// methods
var foo = {
a() {},
b() {}
};
Rule Details
This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.
Each of the following properties would warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w: function() {},
x: function *() {},
[y]: function() {},
z: z
};
In that case the expected syntax would have been:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w() {},
*x() {},
[y]() {},
z
};
This rule does not flag arrow functions inside of object literals. The following will not warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
x: (y) => y
};
Options
The rule takes an option which specifies when it should be applied. It can be set to one of the following values:
-
"always"
(default) expects that the shorthand will be used whenever possible. -
"methods"
ensures the method shorthand is used (also applies to generators). -
"properties"
ensures the property shorthand is used (where the key and variable name match). -
"never"
ensures that no property or method shorthand is used in any object literal. -
"consistent"
ensures that either all shorthand or all longform will be used in an object literal. -
"consistent-as-needed"
ensures that either all shorthand or all longform will be used in an object literal, but ensures all shorthand whenever possible.
You can set the option in configuration like this:
{
"object-shorthand": ["error", "always"]
}
Additionally, the rule takes an optional object configuration:
-
"avoidQuotes": true
indicates that longform syntax is preferred whenever the object key is a string literal (default:false
). Note that this option can only be enabled when the string option is set to"always"
,"methods"
, or"properties"
. -
"ignoreConstructors": true
can be used to prevent the rule from reporting errors for constructor functions. (By default, the rule treats constructors the same way as other functions.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
. -
"avoidExplicitReturnArrows": true
indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule allows either of these.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
.
avoidQuotes
{
"object-shorthand": ["error", "always", { "avoidQuotes": true }]
}
Example of incorrect code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz"() {}
};
Example of correct code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz": function() {},
"qux": qux
};
ignoreConstructors
{
"object-shorthand": ["error", "always", { "ignoreConstructors": true }]
}
Example of correct code for this rule with the "always", { "ignoreConstructors": true }
option:
/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
/*eslint-env es6*/
var foo = {
ConstructorFunction: function() {}
};
avoidExplicitReturnArrows
{
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }]
}
Example of incorrect code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo: (bar, baz) => {
return bar + baz;
},
qux: (foobar) => {
return foobar * 2;
}
};
Example of correct code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo(bar, baz) {
return bar + baz;
},
qux: foobar => foobar * 2
};
Example of incorrect code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a,
b: "foo",
};
Examples of correct code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: "foo"
};
var bar = {
a,
b,
};
Example of incorrect code with the "consistent-as-needed"
option, which is very similar to "consistent"
:
/*eslint object-shorthand: [2, "consistent-as-needed"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: b,
};
When Not To Use It
Anyone not yet in an ES6 environment would not want to apply this rule. Others may find the terseness of the shorthand syntax harder to read and may not want to encourage it with this rule.
Further Reading
Object initializer - MDN Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.get('/api/v1/logout', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.get('/auth/google', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected string concatenation. Open
ctx.redirect('/sync/token?token=' + token)
- Read upRead up
- Exclude checks
Suggest using template literals instead of string concatenation. (prefer-template)
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = "Hello, " + name + "!";
/*eslint-env es6*/
var str = `Hello, ${name}!`;
Rule Details
This rule is aimed to flag usage of +
operators with strings.
Examples
Examples of incorrect code for this rule:
/*eslint prefer-template: "error"*/
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Examples of correct code for this rule:
/*eslint prefer-template: "error"*/
/*eslint-env es6*/
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
When Not To Use It
This rule should not be used in ES3/5 environments.
In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
Related Rules
- [no-useless-concat](no-useless-concat.md)
- [quotes](quotes.md) Source: http://eslint.org/docs/rules/
Missing space after *. Open
.post('/api/v1/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/api/admin/v1/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/auth/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
This generator function does not have 'yield'. Open
}, function *(err, profile) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
This generator function does not have 'yield'. Open
.get('/api/v1/logout', function *(next) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Expected property shorthand. Open
this.body = { token: token }
- Read upRead up
- Exclude checks
Require Object Literal Shorthand Syntax (object-shorthand)
EcmaScript 6 provides a concise form for defining object literal methods and properties. This syntax can make defining complex object literals much cleaner.
Here are a few common examples using the ES5 syntax:
// properties
var foo = {
x: x,
y: y,
z: z,
};
// methods
var foo = {
a: function() {},
b: function() {}
};
Now here are ES6 equivalents:
/*eslint-env es6*/
// properties
var foo = {x, y, z};
// methods
var foo = {
a() {},
b() {}
};
Rule Details
This rule enforces the use of the shorthand syntax. This applies to all methods (including generators) defined in object literals and any properties defined where the key name matches name of the assigned variable.
Each of the following properties would warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w: function() {},
x: function *() {},
[y]: function() {},
z: z
};
In that case the expected syntax would have been:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
w() {},
*x() {},
[y]() {},
z
};
This rule does not flag arrow functions inside of object literals. The following will not warn:
/*eslint object-shorthand: "error"*/
/*eslint-env es6*/
var foo = {
x: (y) => y
};
Options
The rule takes an option which specifies when it should be applied. It can be set to one of the following values:
-
"always"
(default) expects that the shorthand will be used whenever possible. -
"methods"
ensures the method shorthand is used (also applies to generators). -
"properties"
ensures the property shorthand is used (where the key and variable name match). -
"never"
ensures that no property or method shorthand is used in any object literal. -
"consistent"
ensures that either all shorthand or all longform will be used in an object literal. -
"consistent-as-needed"
ensures that either all shorthand or all longform will be used in an object literal, but ensures all shorthand whenever possible.
You can set the option in configuration like this:
{
"object-shorthand": ["error", "always"]
}
Additionally, the rule takes an optional object configuration:
-
"avoidQuotes": true
indicates that longform syntax is preferred whenever the object key is a string literal (default:false
). Note that this option can only be enabled when the string option is set to"always"
,"methods"
, or"properties"
. -
"ignoreConstructors": true
can be used to prevent the rule from reporting errors for constructor functions. (By default, the rule treats constructors the same way as other functions.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
. -
"avoidExplicitReturnArrows": true
indicates that methods are preferred over explicit-return arrow functions for function properties. (By default, the rule allows either of these.) Note that this option can only be enabled when the string option is set to"always"
or"methods"
.
avoidQuotes
{
"object-shorthand": ["error", "always", { "avoidQuotes": true }]
}
Example of incorrect code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz"() {}
};
Example of correct code for this rule with the "always", { "avoidQuotes": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidQuotes": true }]*/
/*eslint-env es6*/
var foo = {
"bar-baz": function() {},
"qux": qux
};
ignoreConstructors
{
"object-shorthand": ["error", "always", { "ignoreConstructors": true }]
}
Example of correct code for this rule with the "always", { "ignoreConstructors": true }
option:
/*eslint object-shorthand: ["error", "always", { "ignoreConstructors": true }]*/
/*eslint-env es6*/
var foo = {
ConstructorFunction: function() {}
};
avoidExplicitReturnArrows
{
"object-shorthand": ["error", "always", { "avoidExplicitReturnArrows": true }]
}
Example of incorrect code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo: (bar, baz) => {
return bar + baz;
},
qux: (foobar) => {
return foobar * 2;
}
};
Example of correct code for this rule with the "always", { "avoidExplicitReturnArrows": true }
option:
/*eslint object-shorthand: ["error", "always", { "avoidExplicitReturnArrows": true }]*/
/*eslint-env es6*/
var foo = {
foo(bar, baz) {
return bar + baz;
},
qux: foobar => foobar * 2
};
Example of incorrect code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a,
b: "foo",
};
Examples of correct code for this rule with the "consistent"
option:
/*eslint object-shorthand: [2, "consistent"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: "foo"
};
var bar = {
a,
b,
};
Example of incorrect code with the "consistent-as-needed"
option, which is very similar to "consistent"
:
/*eslint object-shorthand: [2, "consistent-as-needed"]*/
/*eslint-env es6*/
var foo = {
a: a,
b: b,
};
When Not To Use It
Anyone not yet in an ES6 environment would not want to apply this rule. Others may find the terseness of the shorthand syntax harder to read and may not want to encourage it with this rule.
Further Reading
Object initializer - MDN Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.get('/auth/facebook/request/email', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/auth/google/callback', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/auth/logout', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.post('/auth/register', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
}, function*(err, profile, failed) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected string concatenation. Open
'JWT realm="users", error="invalid_token", error_description="'
- Read upRead up
- Exclude checks
Suggest using template literals instead of string concatenation. (prefer-template)
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = "Hello, " + name + "!";
/*eslint-env es6*/
var str = `Hello, ${name}!`;
Rule Details
This rule is aimed to flag usage of +
operators with strings.
Examples
Examples of incorrect code for this rule:
/*eslint prefer-template: "error"*/
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Examples of correct code for this rule:
/*eslint prefer-template: "error"*/
/*eslint-env es6*/
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
When Not To Use It
This rule should not be used in ES3/5 environments.
In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
Related Rules
- [no-useless-concat](no-useless-concat.md)
- [quotes](quotes.md) Source: http://eslint.org/docs/rules/
Missing space after *. Open
.get('/auth/facebook/callback', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.get('/auth/google/request/email', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.get('/sitemap/:key', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.post('/auth/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
yield passport.authenticate('local', function *(err, profile) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
}, function*(err, profile, failed) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
This generator function does not have 'yield'. Open
.get('/auth/logout', function *(next) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
}, function *(err, profile) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
yield passport.authenticate('local', function *(err, profile) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unnecessary escape character: :. Open
/\/post\/\:id\/edit/,
- Read upRead up
- Exclude checks
Disallow unnecessary escape usage (no-useless-escape)
Escaping non-special characters in strings, template literals, and regular expressions doesn't have any effect, as demonstrated in the following example:
let foo = "hol\a"; // > foo = "hola"
let bar = `${foo}\!`; // > bar = "hola!"
let baz = /\:/ // same functionality with /:/
Rule Details
This rule flags escapes that can be safely removed without changing behavior.
Examples of incorrect code for this rule:
/*eslint no-useless-escape: "error"*/
"\'";
'\"';
"\#";
"\e";
`\"`;
`\"${foo}\"`;
`\#{foo}`;
/\!/;
/\@/;
Examples of correct code for this rule:
/*eslint no-useless-escape: "error"*/
"\"";
'\'';
"\x12";
"\u00a9";
"\371";
"xs\u2111";
`\``;
`\${${foo}\}`;
`$\{${foo}\}`;
/\\/g;
/\t/g;
/\w\$\*\^\./;
When Not To Use It
If you don't want to be notified about unnecessary escapes, you can safely disable this rule. Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.get('/auth/facebook/callback', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected require(). Open
const routeInfo = require('shared/routes').default()
- Read upRead up
- Exclude checks
Enforce require() on the top-level module scope (global-require)
In Node.js, module dependencies are included using the require()
function, such as:
var fs = require("fs");
While require()
may be called anywhere in code, some style guides prescribe that it should be called only in the top level of a module to make it easier to identify dependencies. For instance, it's arguably harder to identify dependencies when they are deeply nested inside of functions and other statements:
function foo() {
if (condition) {
var fs = require("fs");
}
}
Since require()
does a synchronous load, it can cause performance problems when used in other locations.
Further, ES6 modules mandate that import
and export
statements can only occur in the top level of the module's body.
Rule Details
This rule requires all calls to require()
to be at the top level of the module, similar to ES6 import
and export
statements, which also can occur only at the top level.
Examples of incorrect code for this rule:
/*eslint global-require: "error"*/
/*eslint-env es6*/
// calling require() inside of a function is not allowed
function readFile(filename, callback) {
var fs = require('fs');
fs.readFile(filename, callback)
}
// conditional requires like this are also not allowed
if (DEBUG) { require('debug'); }
// a require() in a switch statement is also flagged
switch(x) { case '1': require('1'); break; }
// you may not require() inside an arrow function body
var getModule = (name) => require(name);
// you may not require() inside of a function body as well
function getModule(name) { return require(name); }
// you may not require() inside of a try/catch block
try {
require(unsafeModule);
} catch(e) {
console.log(e);
}
Examples of correct code for this rule:
/*eslint global-require: "error"*/
// all these variations of require() are ok
require('x');
var y = require('y');
var z;
z = require('z').initialize();
// requiring a module and using it in a function is ok
var fs = require('fs');
function readFile(filename, callback) {
fs.readFile(filename, callback)
}
// you can use a ternary to determine which module to require
var logger = DEBUG ? require('dev-logger') : require('logger');
// if you want you can require() at the end of your module
function doSomethingA() {}
function doSomethingB() {}
var x = require("x"),
z = require("z");
When Not To Use It
If you have a module that must be initialized with information that comes from the file-system or if a module is only used in very rare situations and will cause significant overhead to load it may make sense to disable the rule. If you need to require()
an optional dependency inside of a try
/catch
, you can disable this rule for just that dependency using the // eslint-disable-line global-require
comment.
Source: http://eslint.org/docs/rules/
This generator function does not have 'yield'. Open
yield passport.authenticate('local', function *(err, profile) {
- Read upRead up
- Exclude checks
Disallow generator functions that do not have yield
(require-yield)
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
Examples
Examples of incorrect code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don't want to notify generator functions that have no yield
expression, then it's safe to disable this rule.
Related Rules
- [require-await](require-await.md) Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.post('/auth/locale', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected parentheses around single function argument having a body with no curly braces Open
'/c/:cid': map(yield Post.loadAllCid(), (i) => mapKeys(i, (v, k) => 'cid'))
- Read upRead up
- Exclude checks
Require parens in arrow function arguments (arrow-parens)
Arrow functions can omit parentheses when they have exactly one parameter. In all other cases the parameter(s) must be wrapped in parentheses. This rule enforces the consistent use of parentheses in arrow functions.
Rule Details
This rule enforces parentheses around arrow function parameters regardless of arity. For example:
/*eslint-env es6*/
// Bad
a => {}
// Good
(a) => {}
Following this style will help you find arrow functions (=>
) which may be mistakenly included in a condition
when a comparison such as >=
was the intent.
/*eslint-env es6*/
// Bad
if (a => 2) {
}
// Good
if (a >= 2) {
}
The rule can also be configured to discourage the use of parens when they are not required:
/*eslint-env es6*/
// Bad
(a) => {}
// Good
a => {}
Options
This rule has a string option and an object one.
String options are:
-
"always"
(default) requires parens around arguments in all cases. -
"as-needed"
allows omitting parens when there is only one argument.
Object properties for variants of the "as-needed"
option:
-
"requireForBlockBody": true
modifies the as-needed rule in order to require parens if the function body is in an instructions block (surrounded by braces).
always
Examples of incorrect code for this rule with the default "always"
option:
/*eslint arrow-parens: ["error", "always"]*/
/*eslint-env es6*/
a => {};
a => a;
a => {'\n'};
a.then(foo => {});
a.then(foo => a);
a(foo => { if (true) {} });
Examples of correct code for this rule with the default "always"
option:
/*eslint arrow-parens: ["error", "always"]*/
/*eslint-env es6*/
() => {};
(a) => {};
(a) => a;
(a) => {'\n'}
a.then((foo) => {});
a.then((foo) => { if (true) {} });
If Statements
One of benefits of this option is that it prevents the incorrect use of arrow functions in conditionals:
/*eslint-env es6*/
var a = 1;
var b = 2;
// ...
if (a => b) {
console.log('bigger');
} else {
console.log('smaller');
}
// outputs 'bigger', not smaller as expected
The contents of the if
statement is an arrow function, not a comparison.
If the arrow function is intentional, it should be wrapped in parens to remove ambiguity.
/*eslint-env es6*/
var a = 1;
var b = 0;
// ...
if ((a) => b) {
console.log('truthy value returned');
} else {
console.log('falsey value returned');
}
// outputs 'truthy value returned'
The following is another example of this behavior:
/*eslint-env es6*/
var a = 1, b = 2, c = 3, d = 4;
var f = a => b ? c: d;
// f = ?
f
is an arrow function which takes a
as an argument and returns the result of b ? c: d
.
This should be rewritten like so:
/*eslint-env es6*/
var a = 1, b = 2, c = 3, d = 4;
var f = (a) => b ? c: d;
as-needed
Examples of incorrect code for this rule with the "as-needed"
option:
/*eslint arrow-parens: ["error", "as-needed"]*/
/*eslint-env es6*/
(a) => {};
(a) => a;
(a) => {'\n'};
a.then((foo) => {});
a.then((foo) => a);
a((foo) => { if (true) {} });
Examples of correct code for this rule with the "as-needed"
option:
/*eslint arrow-parens: ["error", "as-needed"]*/
/*eslint-env es6*/
() => {};
a => {};
a => a;
a => {'\n'};
a.then(foo => {});
a.then(foo => { if (true) {} });
(a, b, c) => a;
(a = 10) => a;
([a, b]) => a;
({a, b}) => a;
requireForBlockBody
Examples of incorrect code for the { "requireForBlockBody": true }
option:
/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
/*eslint-env es6*/
(a) => a;
a => {};
a => {'\n'};
a.map((x) => x * x);
a.map(x => {
return x * x;
});
a.then(foo => {});
Examples of correct code for the { "requireForBlockBody": true }
option:
/*eslint arrow-parens: [2, "as-needed", { "requireForBlockBody": true }]*/
/*eslint-env es6*/
(a) => {};
(a) => {'\n'};
a => ({});
() => {};
a => a;
a.then((foo) => {});
a.then((foo) => { if (true) {} });
a((foo) => { if (true) {} });
(a, b, c) => a;
(a = 10) => a;
([a, b]) => a;
({a, b}) => a;
Further Reading
- The
"as-needed", { "requireForBlockBody": true }
rule is directly inspired by the Airbnb JS Style Guide. Source: http://eslint.org/docs/rules/
Missing space after *. Open
.get('/auth/facebook/request/email', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/auth/token/verify', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/auth/register', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected string concatenation. Open
this.redirect('/sync/token?token=' + token)
- Read upRead up
- Exclude checks
Suggest using template literals instead of string concatenation. (prefer-template)
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = "Hello, " + name + "!";
/*eslint-env es6*/
var str = `Hello, ${name}!`;
Rule Details
This rule is aimed to flag usage of +
operators with strings.
Examples
Examples of incorrect code for this rule:
/*eslint prefer-template: "error"*/
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Examples of correct code for this rule:
/*eslint prefer-template: "error"*/
/*eslint-env es6*/
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
When Not To Use It
This rule should not be used in ES3/5 environments.
In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
Related Rules
- [no-useless-concat](no-useless-concat.md)
- [quotes](quotes.md) Source: http://eslint.org/docs/rules/
Unexpected space before *. Open
.get('/rss', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.post('/api/admin/v1/login', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected space before *. Open
.post('/api/v1/twblogin', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.post('/api/v1/twblogin', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Missing space after *. Open
.get('/auth/google/request/email', function *(next) {
- Read upRead up
- Exclude checks
Enforce spacing around the * in generator functions (generator-star-spacing)
Generators are a new type of function in ECMAScript 6 that can return multiple values over time.
These special functions are indicated by placing an *
after the function
keyword.
Here is an example of a generator function:
/*eslint-env es6*/
function* generator() {
yield "44";
yield "55";
}
This is also valid:
/*eslint-env es6*/
function *generator() {
yield "44";
yield "55";
}
This is valid as well:
/*eslint-env es6*/
function * generator() {
yield "44";
yield "55";
}
To keep a sense of consistency when using generators this rule enforces a single position for the *
.
Rule Details
This rule aims to enforce spacing around the *
of generator functions.
Options
The rule takes one option, an object, which has two keys before
and after
having boolean values true
or false
.
-
before
enforces spacing between the*
and thefunction
keyword. If it istrue
, a space is required, otherwise spaces are disallowed.
In object literal shorthand methods, spacing before the *
is not checked, as they lack a function
keyword.
-
after
enforces spacing between the*
and the function name (or the opening parenthesis for anonymous generator functions). If it istrue
, a space is required, otherwise spaces are disallowed.
The default is {"before": true, "after": false}
.
An example configuration:
"generator-star-spacing": ["error", {"before": true, "after": false}]
And the option has shorthand as a string keyword:
-
{"before": true, "after": false}
→"before"
-
{"before": false, "after": true}
→"after"
-
{"before": true, "after": true}
→"both"
-
{"before": false, "after": false}
→"neither"
An example of shorthand configuration:
"generator-star-spacing": ["error", "after"]
Examples
before
Examples of correct code for this rule with the "before"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": false}]*/
/*eslint-env es6*/
function *generator() {}
var anonymous = function *() {};
var shorthand = { *generator() {} };
after
Examples of correct code for this rule with the "after"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": true}]*/
/*eslint-env es6*/
function* generator() {}
var anonymous = function* () {};
var shorthand = { * generator() {} };
both
Examples of correct code for this rule with the "both"
option:
/*eslint generator-star-spacing: ["error", {"before": true, "after": true}]*/
/*eslint-env es6*/
function * generator() {}
var anonymous = function * () {};
var shorthand = { * generator() {} };
neither
Examples of correct code for this rule with the "neither"
option:
/*eslint generator-star-spacing: ["error", {"before": false, "after": false}]*/
/*eslint-env es6*/
function*generator() {}
var anonymous = function*() {};
var shorthand = { *generator() {} };
When Not To Use It
If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.
Further Reading
Unexpected string concatenation. Open
'JWT realm="users",error="invalid_token",error_description="'
- Read upRead up
- Exclude checks
Suggest using template literals instead of string concatenation. (prefer-template)
In ES2015 (ES6), we can use template literals instead of string concatenation.
var str = "Hello, " + name + "!";
/*eslint-env es6*/
var str = `Hello, ${name}!`;
Rule Details
This rule is aimed to flag usage of +
operators with strings.
Examples
Examples of incorrect code for this rule:
/*eslint prefer-template: "error"*/
var str = "Hello, " + name + "!";
var str = "Time: " + (12 * 60 * 60 * 1000);
Examples of correct code for this rule:
/*eslint prefer-template: "error"*/
/*eslint-env es6*/
var str = "Hello World!";
var str = `Hello, ${name}!`;
var str = `Time: ${12 * 60 * 60 * 1000}`;
// This is reported by `no-useless-concat`.
var str = "Hello, " + "World!";
When Not To Use It
This rule should not be used in ES3/5 environments.
In ES2015 (ES6) or later, if you don't want to be notified about string concatenation, you can safely disable this rule.
Related Rules
- [no-useless-concat](no-useless-concat.md)
- [quotes](quotes.md) Source: http://eslint.org/docs/rules/
Unexpected if as the only statement in an else block. Open
if (failed) {
- Read upRead up
- Exclude checks
disallow if
statements as the only statement in else
blocks (no-lonely-if)
If an if
statement is the only statement in the else
block, it is often clearer to use an else if
form.
if (foo) {
// ...
} else {
if (bar) {
// ...
}
}
should be rewritten as
if (foo) {
// ...
} else if (bar) {
// ...
}
Rule Details
This rule disallows if
statements as the only statement in else
blocks.
Examples of incorrect code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
} else {
// ...
}
}
Examples of correct code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else if (anotherCondition) {
// ...
}
if (condition) {
// ...
} else if (anotherCondition) {
// ...
} else {
// ...
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
doSomething();
}
When Not To Use It
Disable this rule if the code is clearer without requiring the else if
form.
Source: http://eslint.org/docs/rules/
Unexpected if as the only statement in an else block. Open
if (failed) {
- Read upRead up
- Exclude checks
disallow if
statements as the only statement in else
blocks (no-lonely-if)
If an if
statement is the only statement in the else
block, it is often clearer to use an else if
form.
if (foo) {
// ...
} else {
if (bar) {
// ...
}
}
should be rewritten as
if (foo) {
// ...
} else if (bar) {
// ...
}
Rule Details
This rule disallows if
statements as the only statement in else
blocks.
Examples of incorrect code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
} else {
// ...
}
}
Examples of correct code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else if (anotherCondition) {
// ...
}
if (condition) {
// ...
} else if (anotherCondition) {
// ...
} else {
// ...
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
doSomething();
}
When Not To Use It
Disable this rule if the code is clearer without requiring the else if
form.
Source: http://eslint.org/docs/rules/
Unexpected if as the only statement in an else block. Open
if (err.message === 'user blocked') {
- Read upRead up
- Exclude checks
disallow if
statements as the only statement in else
blocks (no-lonely-if)
If an if
statement is the only statement in the else
block, it is often clearer to use an else if
form.
if (foo) {
// ...
} else {
if (bar) {
// ...
}
}
should be rewritten as
if (foo) {
// ...
} else if (bar) {
// ...
}
Rule Details
This rule disallows if
statements as the only statement in else
blocks.
Examples of incorrect code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
} else {
// ...
}
}
Examples of correct code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else if (anotherCondition) {
// ...
}
if (condition) {
// ...
} else if (anotherCondition) {
// ...
} else {
// ...
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
doSomething();
}
When Not To Use It
Disable this rule if the code is clearer without requiring the else if
form.
Source: http://eslint.org/docs/rules/
Unexpected if as the only statement in an else block. Open
if (err.message === 'user blocked') {
- Read upRead up
- Exclude checks
disallow if
statements as the only statement in else
blocks (no-lonely-if)
If an if
statement is the only statement in the else
block, it is often clearer to use an else if
form.
if (foo) {
// ...
} else {
if (bar) {
// ...
}
}
should be rewritten as
if (foo) {
// ...
} else if (bar) {
// ...
}
Rule Details
This rule disallows if
statements as the only statement in else
blocks.
Examples of incorrect code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
} else {
// ...
}
}
Examples of correct code for this rule:
/*eslint no-lonely-if: "error"*/
if (condition) {
// ...
} else if (anotherCondition) {
// ...
}
if (condition) {
// ...
} else if (anotherCondition) {
// ...
} else {
// ...
}
if (condition) {
// ...
} else {
if (anotherCondition) {
// ...
}
doSomething();
}
When Not To Use It
Disable this rule if the code is clearer without requiring the else if
form.
Source: http://eslint.org/docs/rules/
Similar blocks of code found in 2 locations. Consider refactoring. Open
router
.get('/auth/facebook/callback', function *(next) {
const ctx = this
yield passport.authenticate('facebook', {
failureRedirect: '/login'
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 217.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
router
.get('/auth/google/callback', function *(next) {
const ctx = this
yield passport.authenticate('google', {
failureRedirect: '/login'
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 217.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (errors) {
this.status = 400
this.set('WWW-Authenticate',
'JWT realm="users", error="invalid_token", error_description="'
+ JSON.stringify(errors) + '"')
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 53.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
} catch (err) {
this.status = 401
this.set('WWW-Authenticate',
'JWT realm="users",error="invalid_token",error_description="'
+ JSON.stringify(err) + '"')
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 53.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
router
.get('/auth/google/request/email', function *(next) {
yield passport.authenticate(
'google',
{
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 45.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
router
.get('/auth/facebook/request/email', function *(next) {
yield passport.authenticate(
'facebook',
{
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 45.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Absolute imports should come before relative imports. Open
import db from 'src/server/db'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import hashids from 'src/shared/utils/hashids-plus'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import passport from 'koa-passport'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import config from 'config'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import Sitemap from 'react-router-sitemap';
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import validate from 'parameter'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import Feed from 'feed'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import { isArray, map, mapKeys } from 'lodash'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import * as AuthActions from 'shared/actions/AuthActions'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Expected empty line after require statement not followed by another require. Open
const router = require('koa-router')()
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import moment from 'moment'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/
Absolute imports should come before relative imports. Open
import { nl2br } from 'src/shared/utils/common-utils'
- Read upRead up
- Exclude checks
For more information visit Source: http://eslint.org/docs/rules/