src/content/docs/linter/rules/no-confusing-labels.mdx
import { Tabs, TabItem } from '@astrojs/starlight/components';
<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> ## Summary - Rule available since: `v1.0.0` - Diagnostic Category: [`lint/suspicious/noConfusingLabels`](/reference/diagnostics#diagnostic-category) - This rule is **recommended**, meaning it is enabled by default. - This rule doesn't have a fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Inspired from [`no-labels`](https://eslint.org/docs/latest/rules/no-labels){
"linter": {
"rules": {
"suspicious": {
"noConfusingLabels": "error"
}
}
}
}
Disallow labeled statements that are not loops.
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.
The rule ignores reactive Svelte statements in Svelte components.
label: f();
label: {
f();
break label;
}
label: if (a) {
f()
break label;
}
label: switch (a) {
case 0:
break label;
}
outer: while (a) {
while(b) {
break outer;
}
}
<script>
$: { /* reactive block */ }
</script>
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();