useYield
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/correctness/useYield¥Diagnostic Category:
lint/correctness/useYield -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 error。
¥The default severity of this rule is error.
-
来源:
¥Sources:
-
与
require-yield相同¥Same as
require-yield
-
¥How to configure
{ "linter": { "rules": { "correctness": { "useYield": "error" } } }}¥Description
要求生成器函数包含 yield。
¥Require generator functions to contain yield.
此规则会为没有 yield 关键字的生成器函数生成警告。
¥This rule generates warnings for generator functions that do not have the yield keyword.
¥Examples
¥Invalid
function* foo() { return 10;}code-block.js:1:1 lint/correctness/useYield ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
✖ This generator function doesn’t contain yield.
> 1 │ function* foo() {
│ ^^^^^^^^^^^^^^^^^
> 2 │ return 10;
> 3 │ }
│ ^
4 │
¥Valid
function* foo() { yield 5; return 10;}
function foo() { return 10;}
// This rule does not warn on empty generator functions.function* foo() { }¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号