yield-star-spacing
要求或禁止 yield* 表达式中的 * 周围有空格
此规则报告的一些问题可通过 --fix 命令行 选项自动修复
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.
规则详情
🌐 Rule Details
此规则强制在 yield* 表达式中的 * 周围使用空格。
🌐 This rule enforces spacing around the * in yield* expressions.
选项
🌐 Options
该规则接受一个选项对象,该对象有两个键 before 和 after,其布尔值为 true 或 false。
🌐 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 中引入。