]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/yield-star-spacing.md
bump version to 8.41.0-3
[pve-eslint.git] / eslint / docs / src / rules / yield-star-spacing.md
1 ---
2 title: yield-star-spacing
3 rule_type: layout
4 further_reading:
5 - https://leanpub.com/understandinges6/read/#leanpub-auto-generators
6 ---
7
8
9
10 ## Rule Details
11
12 This rule enforces spacing around the `*` in `yield*` expressions.
13
14 ## Options
15
16 The rule takes one option, an object, which has two keys `before` and `after` having boolean values `true` or `false`.
17
18 * `before` enforces spacing between the `yield` and the `*`.
19 If `true`, a space is required, otherwise spaces are disallowed.
20
21 * `after` enforces spacing between the `*` and the argument.
22 If it is `true`, a space is required, otherwise spaces are disallowed.
23
24 The default is `{"before": false, "after": true}`.
25
26 ```json
27 "yield-star-spacing": ["error", {"before": true, "after": false}]
28 ```
29
30 The option also has a string shorthand:
31
32 * `{"before": false, "after": true}` → `"after"`
33 * `{"before": true, "after": false}` → `"before"`
34 * `{"before": true, "after": true}` → `"both"`
35 * `{"before": false, "after": false}` → `"neither"`
36
37 ```json
38 "yield-star-spacing": ["error", "after"]
39 ```
40
41 ## Examples
42
43 ### after
44
45 Examples of **correct** code for this rule with the default `"after"` option:
46
47 ::: correct
48
49 ```js
50 /*eslint yield-star-spacing: ["error", "after"]*/
51 /*eslint-env es6*/
52
53 function* generator() {
54 yield* other();
55 }
56 ```
57
58 :::
59
60 ### before
61
62 Examples of **correct** code for this rule with the `"before"` option:
63
64 ::: correct
65
66 ```js
67 /*eslint yield-star-spacing: ["error", "before"]*/
68 /*eslint-env es6*/
69
70 function *generator() {
71 yield *other();
72 }
73 ```
74
75 :::
76
77 ### both
78
79 Examples of **correct** code for this rule with the `"both"` option:
80
81 ::: correct
82
83 ```js
84 /*eslint yield-star-spacing: ["error", "both"]*/
85 /*eslint-env es6*/
86
87 function * generator() {
88 yield * other();
89 }
90 ```
91
92 :::
93
94 ### neither
95
96 Examples of **correct** code for this rule with the `"neither"` option:
97
98 ::: correct
99
100 ```js
101 /*eslint yield-star-spacing: ["error", "neither"]*/
102 /*eslint-env es6*/
103
104 function*generator() {
105 yield*other();
106 }
107 ```
108
109 :::
110
111 ## When Not To Use It
112
113 If your project will not be using generators or you are not concerned with spacing consistency, you do not need this rule.