Skip to content

noUnusedLabels

诊断类别:lint/correctness/noUnusedLabels

¥Diagnostic Category: lint/correctness/noUnusedLabels

自从:v1.0.0

¥Since: v1.0.0

来源:

¥Sources:

禁止未使用的标签。

¥Disallow unused labels.

声明但从未使用的标签很可能是由于重构不完整而导致的错误。

¥Labels that are declared and never used are most likely an error due to incomplete refactoring.

该规则忽略 Svelte 组件中的反应式 Svelte 语句。

¥The rule ignores reactive Svelte statements in Svelte components.

¥Examples

¥Invalid

LOOP: 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

LOOP: 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>

¥Related links