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

强制在 yield* 表达式中 * 周围使用空格 (yield-star-spacing)

The --fix option on the command line can automatically fix some of the problems reported by this rule.

命令行中的 --fix 选项可以自动修复一些该规则报告的问题。

Rule Details

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

该规则强制在 yield* 表达式中 * 左右使用空格。

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

使用此规则,你需要使用 es6 环境parserOptions中设置 ecmaVersion6

Options

The rule takes one option, an object, which has two keys before and after having boolean values true or false.

该规则有一个对象选项,两个属性 beforeafter,值为 truefalse

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

默认为 {"before": false, "after": true}

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

The option also has a string shorthand:

该选项也有简写形式:

"yield-star-spacing": ["error", "after"]

Examples

after

Examples of correct code for this rule with the default "after" option:

默认选项 "after"正确 代码示例:

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

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

before

Examples of correct code for this rule with the "before" option:

选项 "before"正确 代码示例:

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

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

both

Examples of correct code for this rule with the "both" option:

选项 "both"正确 代码示例:

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

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

neither

Examples of correct code for this rule with the "neither" option:

选项 "neither"正确 代码示例:

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

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

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.

如果你的项目不使用 generator 函数或你不关心空格的一致性,你不需要使用此规则。

Further Reading

Version

This rule was introduced in ESLint 2.0.0-alpha-1.

该规则在 ESLint 2.0.0-alpha-1 中被引入。

Resources