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