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.

What it does ​

Disallow unused labels.

Why is this bad? ​

Labels that are declared and not used anywhere in the code are most likely an error due to incomplete refactoring.

Examples ​

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

How to use ​

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

Version ​

This rule was added in v0.0.3.

References ​