查找缺失的 yield 语句
Find missing yield statements
我正在寻找一种方法来查找代码中的位置(例如在 Atom 中使用 jslint 进行验证),其中函数是用 * 定义的,但是在调用它时没有指定 "yield"。我经常忘记 "yield",想 remind/validate 这个对我有用。有办法吗?原子包也许?
举例说明:
let f = function* () {
yield doAsyncStuff();
yield doMoreAsyncStuff();
let res = yield fetchAsyncStuff();
return res;
}
let caller = function* () {
yield anotherFunction();
let res = x(); // <-- here I have missed the yield
}
Eslint has a rule called require-yield
检测生成器函数中是否没有使用 yield
关键字。但是在你的 caller
函数中,你在调用 anotherFunction
时已经有一个 yield
,并且由于在调用 x
函数时不使用 yield
可能是逻辑的一部分在您的代码背后,没有合乎逻辑的方法来检测那里缺少的 yield
。
顺便说一句,这个问题已经讨论得很多,但不可行:Rule Idea: Ensure yield on call to generator function
我正在寻找一种方法来查找代码中的位置(例如在 Atom 中使用 jslint 进行验证),其中函数是用 * 定义的,但是在调用它时没有指定 "yield"。我经常忘记 "yield",想 remind/validate 这个对我有用。有办法吗?原子包也许?
举例说明:
let f = function* () {
yield doAsyncStuff();
yield doMoreAsyncStuff();
let res = yield fetchAsyncStuff();
return res;
}
let caller = function* () {
yield anotherFunction();
let res = x(); // <-- here I have missed the yield
}
Eslint has a rule called require-yield
检测生成器函数中是否没有使用 yield
关键字。但是在你的 caller
函数中,你在调用 anotherFunction
时已经有一个 yield
,并且由于在调用 x
函数时不使用 yield
可能是逻辑的一部分在您的代码背后,没有合乎逻辑的方法来检测那里缺少的 yield
。
顺便说一句,这个问题已经讨论得很多,但不可行:Rule Idea: Ensure yield on call to generator function