mirror of
https://github.com/airbnb/javascript.git
synced 2026-01-14 08:38:08 -05:00
[eslint config] [base] [breaking] Enforce proper generator star spacing.
Fixes #887.
This commit is contained in:
44
README.md
44
README.md
@@ -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)**
|
||||
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user