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