Versions

no-label-var

Disallow labels that share a name with a variable

规则细节

这条规则旨在创建更清晰的代码,不允许创建一个与范围内的变量同名的标签的坏做法。

使用此规则的错误示例:

Open in Playground
/*eslint no-label-var: "error"*/

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

使用此规则的正确示例:

Open in Playground
/*eslint no-label-var: "error"*/

// 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;
  }
}

何时不用

如果你不希望被通知标签的使用情况,你可以安全地禁用此规则。

Version

This rule was introduced in ESLint v0.0.9.

Resources

更改语言