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.
Examples
Section titled “Examples”function* emptyGenerator() { console.log("No yield here");}
function* generatorThatReturns() { return 42;}
class Collection { *iterator() { this.process(); }}
function* numbers() { yield 1; yield 2; yield 3;}
function* range(start: number, end: number) { for (let i = start; i < end; i++) { yield i; }}
class Collection { *iterator() { yield* this.items; }}
Options
Section titled “Options”This rule is not configurable.
When Not To Use It
Section titled “When Not To Use It”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.
Further Reading
Section titled “Further Reading”Equivalents in Other Linters
Section titled “Equivalents in Other Linters”- Biome:
useYield
- Deno:
require-yield
- ESLint:
require-yield
- Oxlint:
eslint/require-yield
Made with ❤️🔥 in Boston by
Josh Goldberg and contributors.