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