Back to Eslint

require-yield

docs/src/rules/require-yield.md

10.3.0698 B
Original Source

Rule Details

This rule generates warnings for generator functions that do not have the yield keyword.

Examples of incorrect code for this rule:

::: incorrect

js
/*eslint require-yield: "error"*/

function* foo() {
  return 10;
}

:::

Examples of correct code for this rule:

::: correct

js
/*eslint require-yield: "error"*/

function* foo() {
  yield 5;
  return 10;
}

function bar() {
  return 10;
}

// This rule does not warn on empty generator functions.
function* baz() { }

:::

Options

This rule has no options.

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.