]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/rules/require-yield.md
first commit
[pve-eslint.git] / eslint / docs / rules / require-yield.md
1 # Disallow generator functions that do not have `yield` (require-yield)
2
3 ## Rule Details
4
5 This rule generates warnings for generator functions that do not have the `yield` keyword.
6
7 ## Examples
8
9 Examples of **incorrect** code for this rule:
10
11 ```js
12 /*eslint require-yield: "error"*/
13 /*eslint-env es6*/
14
15 function* foo() {
16 return 10;
17 }
18 ```
19
20 Examples of **correct** code for this rule:
21
22 ```js
23 /*eslint require-yield: "error"*/
24 /*eslint-env es6*/
25
26 function* foo() {
27 yield 5;
28 return 10;
29 }
30
31 function foo() {
32 return 10;
33 }
34
35 // This rule does not warn on empty generator functions.
36 function* foo() { }
37 ```
38
39 ## When Not To Use It
40
41 If you don't want to notify generator functions that have no `yield` expression, then it's safe to disable this rule.
42
43 ## Related Rules
44
45 * [require-await](require-await.md)