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