require-yield
NOTE: this rule is part of the
recommended
rule set.Enable full set in
deno.json
:{ "lint": { "tags": ["recommended"] } }
Enable full set using the Deno CLI:
deno lint --tags=recommended
Disallows generator functions that have no yield
.
JavaScript provides generator functions expressed as function*
, where we can
pause and later resume the function execution at the middle points. At these
points we use the yield
keyword. In other words, it makes no sense at all to
create generator functions that contain no yield
keyword, since such functions
could be written as normal functions.
Invalid:
function* f1() {
return "f1";
}
Valid:
function* f1() {
yield "f1";
}
// generator function with empty body is allowed
function* f2() {}
function f3() {
return "f3";
}