# generator-without-yield

Rule `sonarjs/generator-without-yield`. Generators should explicitly "yield" a value

- Source: sonarjs
- Technologies: JavaScript
- Kind: correctness
- Needs type information: no
- Autofix: no
- Reach: 6.2M weekly downloads of presets that enable it
- Trend: +62.1% last quarter
- Rank: #1220 by reach, #521 by growth

## Linters

| Linter | Rule name | Recommended | Autofix | Details | Docs |
| --- | --- | --- | --- | --- | --- |
| ESLint | `sonarjs/generator-without-yield` | yes | no | package `eslint-plugin-sonarjs` | [docs](https://rules.sonarsource.com/javascript/RSPEC-3531/) |

## Code examples

### Incorrect: the rule reports this

```js
function* myGen(a, b) {  // Noncompliant
  let answer = 0;
  answer += a * b;
}
```

### Correct: the rule accepts this

```js
function* myGen(a, b) {
  let answer = 0;
  while (answer < 42) {
    answer += a * b;
    yield answer;
  }
}
```

Examples from the ESLint documentation.

## Enable it

### ESLint: `eslint.config.js`

```js
export default [
  {
    rules: {
      "sonarjs/generator-without-yield": "error",
    },
  },
];
```

## Presets that enable it

| Preset | Linter | Package | Rules | Weekly downloads | Trend |
| --- | --- | --- | --- | --- | --- |
| [SonarJS recommended](https://lintradar.dev/presets/sonarjs-recommended.md) | ESLint | `eslint-plugin-sonarjs` | 230 | 6.2M | +62.1% |

## Related rules

- [sonarjs/future-reserved-words](https://lintradar.dev/rules/sonarjs/future-reserved-words.md): Future reserved words should not be used as identifiers
- [sonarjs/hardcoded-secret-signatures](https://lintradar.dev/rules/sonarjs/hardcoded-secret-signatures.md): Credentials should not be hard-coded
- [sonarjs/function-return-type](https://lintradar.dev/rules/sonarjs/function-return-type.md): Functions should always return the same type
- [sonarjs/hashing](https://lintradar.dev/rules/sonarjs/hashing.md): Weak hashing algorithms should not be used
- [sonarjs/function-inside-loop](https://lintradar.dev/rules/sonarjs/function-inside-loop.md): Functions should not be defined inside loops
- [sonarjs/hooks-before-test-cases](https://lintradar.dev/rules/sonarjs/hooks-before-test-cases.md): Lifecycle hooks should not be interleaved with test cases or nested suites

---

Web page: https://lintradar.dev/rules/sonarjs/generator-without-yield. Data from npm and the linters' documentation, collected Dec 4, 2026. Site guide for agents: https://lintradar.dev/llms.txt
