Skip to content
← Back to rules

eslint/no-unused-labels Correctness

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

如何使用

To enable this rule using the config file or in the CLI, you can use:

json
{
  "rules": {
    "no-unused-labels": "error"
  }
}
ts
import { defineConfig } from "oxlint";

export default defineConfig({
  rules: {
    "no-unused-labels": "error",
  },
});
bash
oxlint --deny no-unused-labels

版本

此规则于 v0.0.3 中添加。

参考资料