首页
学习
活动
专区
工具
TVP
发布

no-label-var

规则细节

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

此规则的错误代码示例:

/*eslint no-label-var: "error"*/

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

此规则的正确代码示例:

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

何时不使用它

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

相关规则

  • no-extra-label
  • no-labels
  • no-unused-labels

版本

该规则在 ESLint 0.0.9 中引入。

资源

扫码关注腾讯云开发者

领取腾讯云代金券