Index

yield-star-spacing

要求或禁止 yield* 表达式中的 * 周围有空格

🔧 Fixable

此规则报告的一些问题可通过 --fix 命令行 选项自动修复

Important

This rule was deprecated in ESLint v8.53.0. It will be removed in v11.0.0. Please use the corresponding rule in @stylistic/eslint-plugin.

Learn more

规则详情

🌐 Rule Details

此规则强制在 yield* 表达式中的 * 周围使用空格。

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

选项

🌐 Options

该规则接受一个选项对象,该对象有两个键 beforeafter,其布尔值为 truefalse

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

  • before 强制在 yield* 之间留空格。如果是 true,则需要空格,否则不允许空格。
  • after 强制在 * 和参数之间保持间距。如果它是 true,则需要空格,否则不允许空格。

默认值是 {"before": false, "after": true}

🌐 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"]

after

使用默认 "after" 选项时,该规则的正确代码示例:

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

在线运行
/*eslint yield-star-spacing: ["error", "after"]*/

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

before

使用 "before" 选项时,此规则的正确代码示例:

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

在线运行
/*eslint yield-star-spacing: ["error", "before"]*/

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

both

使用 "both" 选项时,此规则的正确代码示例:

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

在线运行
/*eslint yield-star-spacing: ["error", "both"]*/

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

neither

使用 "neither" 选项时,此规则的正确代码示例:

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

在线运行
/*eslint yield-star-spacing: ["error", "neither"]*/

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.

版本

此规则是在 ESLint v2.0.0-alpha-1 中引入。

进阶读物

资源