From 8e125fa07cd9214b5e31e59095707ffae3284d13 Mon Sep 17 00:00:00 2001 From: Jordan Harband Date: Tue, 17 May 2016 21:27:10 -0700 Subject: [PATCH] [eslint config] [base] [breaking] Enforce proper generator star spacing. Fixes #887. --- README.md | 44 +++++++++++++++++++ .../eslint-config-airbnb-base/rules/es6.js | 3 +- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 38699c80..fb43bc9e 100644 --- a/README.md +++ b/README.md @@ -1219,6 +1219,50 @@ Other Style Guides > Why? They don't transpile well to ES5. + + - [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)** diff --git a/packages/eslint-config-airbnb-base/rules/es6.js b/packages/eslint-config-airbnb-base/rules/es6.js index 57aa01e7..ed70f8bf 100644 --- a/packages/eslint-config-airbnb-base/rules/es6.js +++ b/packages/eslint-config-airbnb-base/rules/es6.js @@ -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