]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/src/rules/no-extra-label.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / rules / no-extra-label.md
CommitLineData
8f9d1d4d
DC
1---
2title: no-extra-label
8f9d1d4d
DC
3rule_type: suggestion
4related_rules:
5- no-labels
6- no-label-var
7- no-unused-labels
8---
9
10
eb39fafa
DC
11
12If a loop contains no nested loops or switches, labeling the loop is unnecessary.
13
14```js
15A: while (a) {
16 break A;
17}
18```
19
20You can achieve the same result by removing the label and using `break` or `continue` without a label.
21Probably those labels would confuse developers because they expect labels to jump to further.
22
23## Rule Details
24
25This rule is aimed at eliminating unnecessary labels.
26
27Examples of **incorrect** code for this rule:
28
8f9d1d4d
DC
29::: incorrect
30
eb39fafa
DC
31```js
32/*eslint no-extra-label: "error"*/
33
34A: while (a) {
35 break A;
36}
37
38B: for (let i = 0; i < 10; ++i) {
39 break B;
40}
41
42C: switch (a) {
43 case 0:
44 break C;
45}
46```
47
8f9d1d4d
DC
48:::
49
eb39fafa
DC
50Examples of **correct** code for this rule:
51
8f9d1d4d
DC
52::: correct
53
eb39fafa
DC
54```js
55/*eslint no-extra-label: "error"*/
56
57while (a) {
58 break;
59}
60
61for (let i = 0; i < 10; ++i) {
62 break;
63}
64
65switch (a) {
66 case 0:
67 break;
68}
69
70A: {
71 break A;
72}
73
74B: while (a) {
75 while (b) {
76 break B;
77 }
78}
79
80C: switch (a) {
81 case 0:
82 while (b) {
83 break C;
84 }
85 break;
86}
87```
88
8f9d1d4d
DC
89:::
90
eb39fafa
DC
91## When Not To Use It
92
93If you don't want to be notified about usage of labels, then it's safe to disable this rule.