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