]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-label-var.md
422538a934d00790152215e818d0e8e3e4b6465c
[pve-eslint.git] / eslint / docs / src / rules / no-label-var.md
1 ---
2 title: no-label-var
3 layout: doc
4 rule_type: suggestion
5 related_rules:
6 - no-extra-label
7 - no-labels
8 - no-unused-labels
9 ---
10
11
12 ## Rule Details
13
14 This rule aims to create clearer code by disallowing the bad practice of creating a label that shares a name with a variable that is in scope.
15
16 Examples of **incorrect** code for this rule:
17
18 ::: incorrect
19
20 ```js
21 /*eslint no-label-var: "error"*/
22
23 var x = foo;
24 function bar() {
25 x:
26 for (;;) {
27 break x;
28 }
29 }
30 ```
31
32 :::
33
34 Examples of **correct** code for this rule:
35
36 ::: correct
37
38 ```js
39 /*eslint no-label-var: "error"*/
40
41 // The variable that has the same name as the label is not in scope.
42
43 function foo() {
44 var q = t;
45 }
46
47 function bar() {
48 q:
49 for(;;) {
50 break q;
51 }
52 }
53 ```
54
55 :::
56
57 ## When Not To Use It
58
59 If you don't want to be notified about usage of labels, then it's safe to disable this rule.