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