Skip to content

Latest commit

 

History

History
54 lines (38 loc) · 798 Bytes

no-label-var.md

File metadata and controls

54 lines (38 loc) · 798 Bytes
规则名 规则类型 关联规则
no-label-var
suggestion
no-extra-label
no-labels
no-unused-labels

规则详解

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.

此规则的 错误 代码实例:

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

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

此规则的 正确 代码实例:

::: correct

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

禁用建议

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