Skip to content

generatorFunctionYields

Reports generator functions that do not yield values.

✅ This rule is included in the ts logical preset.

Generator functions use the function* syntax to create iterators that can produce multiple values over time. Without a yield expression, the generator will not produce any values and behaves like an empty iterator. This is likely unintentional and indicates incomplete implementation or a misunderstanding of generator functions.

function* emptyGenerator() {
console.log("No yield here");
}
function* generatorThatReturns() {
return 42;
}
class Collection {
*iterator() {
this.process();
}
}

This rule is not configurable.

If you intentionally want to create generator functions that produce no values (empty iterators), you can disable this rule. However, in most cases, such functions should not be generators.

Made with ❤️‍🔥 in Boston by Josh Goldberg and contributors.