[eslint config] [base] [breaking] Enforce proper generator star spacing.

Fixes #887.
This commit is contained in:
Jordan Harband
2016-05-17 21:27:10 -07:00
parent 312cd01a95
commit 8e125fa07c
2 changed files with 46 additions and 1 deletions

View File

@@ -1219,6 +1219,50 @@ Other Style Guides
> Why? They don't transpile well to ES5.
<a name="generators--spacing"></a>
- [11.3](#generators--spacing) If you must use generators, or if you disregard [our advice](#generators--nope), make sure their function signature is spaced properly. eslint: [`generator-star-spacing`](http://eslint.org/docs/rules/generator-star-spacing)
> Why? `function` and `*` are part of the same conceptual keyword - `*` is not a modifier for `function`, `function*` is a unique construct, different from `function`.
```js
// bad
function * foo() {
}
const bar = function * () {
}
const baz = function *() {
}
const quux = function*() {
}
function*foo() {
}
function *foo() {
}
// very bad
function
*
foo() {
}
const wat = function
*
() {
}
// good
function* foo() {
}
const foo = function* () {
}
```
**[⬆ back to top](#table-of-contents)**

View File

@@ -27,7 +27,8 @@ module.exports = {
'constructor-super': 0,
// enforce the spacing around the * in generator functions
'generator-star-spacing': 0,
// http://eslint.org/docs/rules/generator-star-spacing
'generator-star-spacing': [2, { 'before': false, 'after': true }],
// disallow modifying variables of class declarations
// http://eslint.org/docs/rules/no-class-assign