Skip to content

noConfusingLabels

诊断类别:lint/suspicious/noConfusingLabels

¥Diagnostic Category: lint/suspicious/noConfusingLabels

自从:v1.0.0

¥Since: v1.0.0

来源:

¥Sources:

禁止非循环的标记语句。

¥Disallow labeled statements that are not loops.

JavaScript 中的标签语句与 breakcontinue 结合使用,以控制多个循环周围的流程。它们对其他语句的使用是可疑且不熟悉的。

¥Labeled statements in JavaScript are used in conjunction with break and continue to control flow around multiple loops. Their use for other statements is suspicious and unfamiliar.

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

¥The rule ignores reactive Svelte statements in Svelte components.

¥Examples

¥Invalid

label: f();
code-block.js:1:1 lint/suspicious/noConfusingLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected label.

> 1 │ label: f();
^^^^^
2 │

Only loops should be labeled.
The use of labels for other statements is suspicious and unfamiliar.

label: {
f();
break label;
}
code-block.js:1:1 lint/suspicious/noConfusingLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected label.

> 1 │ label: {
^^^^^
2 │ f();
3 │ break label;

Only loops should be labeled.
The use of labels for other statements is suspicious and unfamiliar.

label: if (a) {
f()
break label;
}
code-block.js:1:1 lint/suspicious/noConfusingLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected label.

> 1 │ label: if (a) {
^^^^^
2 │ f()
3 │ break label;

Only loops should be labeled.
The use of labels for other statements is suspicious and unfamiliar.

label: switch (a) {
case 0:
break label;
}
code-block.js:1:1 lint/suspicious/noConfusingLabels ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Unexpected label.

> 1 │ label: switch (a) {
^^^^^
2 │ case 0:
3 │ break label;

Only loops should be labeled.
The use of labels for other statements is suspicious and unfamiliar.

¥Valid

outer: while (a) {
while(b) {
break outer;
}
}
<script>
$: { /* reactive block */ }
</script>

¥Related links