no-label-var

禁止与变量共享名称的标签

规则详情

¥Rule Details

此规则旨在通过禁止创建与范围内的变量共享名称的标签的不良做法来创建更清晰的代码。

¥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.

此规则的错误代码示例:

¥Examples of incorrect code for this rule:

在线运行
/*eslint no-label-var: "error"*/

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

此规则的正确代码示例:

¥Examples of correct code for this rule:

在线运行
/*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;
  }
}

何时不使用

¥When Not To Use It

如果你不想收到有关标签使用情况的通知,那么禁用此规则是安全的。

¥If you don’t want to be notified about usage of labels, then it’s safe to disable this rule.

版本

此规则是在 ESLint v0.0.9 中引入。

资源

ESLint 中文网
粤ICP备13048890号