Skip to content

Latest commit

 

History

History
87 lines (59 loc) · 2.28 KB

yield-star-spacing.md

File metadata and controls

87 lines (59 loc) · 2.28 KB

Enforce spacing around the * in yield* expressions (yield-star-spacing)

(fixable) The --fix option on the command line automatically fixes problems reported by this rule.

Rule Details

This rule enforces spacing around the * in yield* expressions.

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 yield and the *. If true, a space is required, otherwise spaces are disallowed.

  • after enforces spacing between the * and the argument. If it is true, a space is required, otherwise spaces are disallowed.

The default is {"before": false, "after": true}.

"yield-star-spacing": ["error", {"before": true, "after": false}]

The option also has a string shorthand:

  • {"before": false, "after": true}"after"
  • {"before": true, "after": false}"before"
  • {"before": true, "after": true}"both"
  • {"before": false, "after": false}"neither"
"yield-star-spacing": ["error", "after"]

When using "after" this spacing will be enforced:

/*eslint yield-star-spacing: ["error", "after"]*/
/*eslint-env es6*/

function* generator() {
  yield* other();
}

When using "before" this spacing will be enforced:

/*eslint yield-star-spacing: ["error", "before"]*/
/*eslint-env es6*/

function *generator() {
  yield *other();
}

When using "both" this spacing will be enforced:

/*eslint yield-star-spacing: ["error", "both"]*/
/*eslint-env es6*/

function * generator() {
  yield * other();
}

When using "neither" this spacing will be enforced:

/*eslint yield-star-spacing: ["error", "neither"]*/
/*eslint-env es6*/

function*generator() {
  yield*other();
}

To use this rule you either need to use the es6 environment or set ecmaVersion to 6 in parserOptions.

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