Skip to content

eslint/no-label-var Style

What it does

Disallow labels that share a name with a variable.

Why is this bad?

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.

Example

Examples of incorrect code for this rule:

js
var x = foo;
function bar() {
  x: for (;;) {
    break x;
  }
}

Examples of correct code for this rule:

js
// The variable that has the same name as the label is not in scope.

function foo() {
  var q = t;
}

function bar() {
  q: for (;;) {
    break q;
  }
}

How to use

To enable this rule in the CLI or using the config file, you can use:

bash
oxlint --deny no-label-var
json
{
  "rules": {
    "no-label-var": "error"
  }
}

References

Released under the MIT License.