noUnusedLabels
Summary
Section titled Summary- Rule available since:
v1.0.0
- Diagnostic Category:
lint/correctness/noUnusedLabels
- This rule is recommended, which means is enabled by default.
- This rule has a safe fix.
- The default severity of this rule is warning.
- Sources:
- Same as
no-unused-labels
- Same as
Description
Section titled DescriptionDisallow unused labels.
Labels that are declared and never used are most likely an error due to incomplete refactoring.
The rule ignores reactive Svelte statements in Svelte components.
Examples
Section titled ExamplesInvalid
Section titled InvalidLOOP: for (const x of xs) { if (x > 0) { break; } f(x);}
code-block.js:1:1 lint/correctness/noUnusedLabels FIXABLE ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
⚠ Unused label.
> 1 │ LOOP: for (const x of xs) {
│ ^^^^
2 │ if (x > 0) {
3 │ break;
ℹ The label is not used by any break statement and continue statement.
ℹ Safe fix: Remove the unused label.
1 │ LOOP:·for·(const·x·of·xs)·{
│ ------
Valid
Section titled ValidLOOP: for (const x of xs) { if (x > 0) { break LOOP; } f(x);}
function nonNegative(n) { DEV: assert(n >= 0); return n;}
<script>$: { /* reactive block */ }</script>
How to configure
Section titled How to configure{ "linter": { "rules": { "correctness": { "noUnusedLabels": "error" } } }}