noConfusingLabels
¥Summary
-
规则生效日期:
v1.0.0¥Rule available since:
v1.0.0 -
诊断类别:
lint/suspicious/noConfusingLabels¥Diagnostic Category:
lint/suspicious/noConfusingLabels -
此规则为推荐规则,默认启用。
¥This rule is recommended, which means is enabled by default.
-
此规则没有修复方案。
¥This rule doesn’t have a fix.
-
此规则的默认严重级别为 warning。
¥The default severity of this rule is warning.
-
来源:
¥Sources:
¥How to configure
{ "linter": { "rules": { "suspicious": { "noConfusingLabels": "error" } } }}¥Description
禁止非循环的标记语句。
¥Disallow labeled statements that are not loops.
JavaScript 中的标签语句与 break 和 continue 结合使用,以控制多个循环周围的流程。它们对其他语句的使用是可疑且不熟悉的。
¥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>¥Options
使用以下选项允许在代码中使用特定标签。标签可用于标记在特定情况下(例如在生产版本中)应删除的代码。一些打包工具,例如 esbuild 和 Vite,可以配置为移除带标签的语句。
¥Use the options to allow specific labels in your code. Labels can be used to mark code that should be removed under certain conditions, such as in production builds. Some bundlers, such as esbuild and Vite, can be configured to remove labeled statements.
{ "linter": { "rules": { "suspicious": { "noConfusingLabels": { "options": { "allowedLabels": [ "DEV" ] } } } } }}DEV: assertSomeCondition();¥Related links
Biome v2.1 中文网 - 粤ICP备13048890号