]> git.proxmox.com Git - pve-eslint.git/blame - eslint/docs/rules/no-unused-labels.md
bump version to 8.4.0-3
[pve-eslint.git] / eslint / docs / rules / no-unused-labels.md
CommitLineData
eb39fafa
DC
1# Disallow Unused Labels (no-unused-labels)
2
3Labels that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring.
4
5```js
6OUTER_LOOP:
7for (const student of students) {
8 if (checkScores(student.scores)) {
9 continue;
10 }
11 doSomething(student);
12}
13```
14
15In this case, probably removing `OUTER_LOOP:` had been forgotten.
16Such labels take up space in the code and can lead to confusion by readers.
17
18## Rule Details
19
20This rule is aimed at eliminating unused labels.
21
22Examples of **incorrect** code for this rule:
23
24```js
25/*eslint no-unused-labels: "error"*/
26
27A: var foo = 0;
28
29B: {
30 foo();
31}
32
33C:
34for (let i = 0; i < 10; ++i) {
35 foo();
36}
37```
38
39Examples of **correct** code for this rule:
40
41```js
42/*eslint no-unused-labels: "error"*/
43
44A: {
45 if (foo()) {
46 break A;
47 }
48 bar();
49}
50
51B:
52for (let i = 0; i < 10; ++i) {
53 if (foo()) {
54 break B;
55 }
56 bar();
57}
58```
59
60## When Not To Use It
61
62If you don't want to be notified about unused labels, then it's safe to disable this rule.
63
64## Related Rules
65
66* [no-extra-label](./no-extra-label.md)
67* [no-labels](./no-labels.md)
68* [no-label-var](./no-label-var.md)