Disallow generator functions that do not have yield
(require-yield)
禁用函数内没有yield
的 generator 函数
The "extends": "eslint:recommended"
property in a configuration file enables this rule.
配置文件中的 "extends": "eslint:recommended"
属性启用了此规则。
Rule Details
This rule generates warnings for generator functions that do not have the yield
keyword.
如果 generator 函数内部没有yield
关键字,该规则将发出警告。
Examples
Examples of incorrect code for this rule:
错误 代码示例:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
return 10;
}
Examples of correct code for this rule:
正确 代码示例:
/*eslint require-yield: "error"*/
/*eslint-env es6*/
function* foo() {
yield 5;
return 10;
}
function foo() {
return 10;
}
// This rule does not warn on empty generator functions.
function* foo() { }
When Not To Use It
If you don’t want to notify generator functions that have no yield
expression, then it’s safe to disable this rule.
如果伱不想被通知 generator 函数没有 yield
表达式,关闭此规则即可。
Related Rules
Version
This rule was introduced in ESLint 1.0.0-rc-1.
该规则在 ESLint 1.0.0-rc-1 中被引入。