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,则需要空格,否则不允许使用空格。¥
beforeenforces spacing between theyieldand the*. Iftrue, a space is required, otherwise spaces are disallowed. -
after强制*和参数之间的间距。如果是true,则需要空格,否则不允许空格。¥
afterenforces spacing between the*and the argument. If it istrue, a space is required, otherwise spaces are disallowed.
默认值为 {"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"]
示例
¥Examples
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 中引入。