Skip to content
← Back to rules

eslint/no-unused-labels 正确性

This rule is turned on by default.
An auto-fix is available for this rule.

它做了什么

禁止未使用的标签。

为什么这是个问题

在代码中声明但未被使用的标签,很可能是由于重构不完整而导致的错误。

示例

此规则的错误代码示例:

javascript
OUTER_LOOP: for (const student of students) {
  if (checkScores(student.scores)) {
    continue;
  }
  doSomething(student);
}

此规则的正确代码示例:

javascript
for (const student of students) {
  if (checkScores(student.scores)) {
    continue;
  }
  doSomething(student);
}

如何使用

要通过配置文件或 CLI 启用此规则,可以使用:

json
{
  "rules": {
    "no-unused-labels": "error"
  }
}
bash
oxlint --deny no-unused-labels

参考资料