Back to Biomejs

noContinue

src/content/docs/linter/rules/no-continue.mdx

latest3.9 KB
Original Source

import { Tabs, TabItem } from '@astrojs/starlight/components';

<Tabs> <TabItem label="JavaScript (and super languages)" icon="seti:javascript"> :::caution This rule is part of the [nursery](/linter/#nursery) group. This means that it is experimental and the behavior can change at any time. ::: ## Summary - Rule available since: `v2.3.4` - Diagnostic Category: [`lint/nursery/noContinue`](/reference/diagnostics#diagnostic-category) - This rule doesn't have a fix. - The default severity of this rule is [**information**](/reference/diagnostics#information). - Sources: - Same as [`no-continue`](https://eslint.org/docs/latest/rules/no-continue)

How to configure

json
{
	"linter": {
		"rules": {
			"nursery": {
				"noContinue": "error"
			}
		}
	}
}

Description

Disallow continue statements.

The continue statement terminates execution of the statements in the current iteration of the current or labeled loop, and continues execution of the loop with the next iteration. When used incorrectly it makes code less testable, less readable and less maintainable. Structured control flow statements such as if should be used instead.

Examples

Invalid

js
let sum = 0,
    i;

for(i = 0; i < 10; i++) {
    if(i >= 5) {
        continue;
    }

    sum += i;
}
<pre class="language-text"><code class="language-text">code-block.js:6:9 <a href="https://biomejs.dev/linter/rules/no-continue">lint/nursery/noContinue</a> ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">Unexpected use of continue statement.</span> <strong>4 │ </strong>for(i = 0; i &lt; 10; i++) &#123; <strong>5 │ </strong> if(i &gt;= 5) &#123; <strong><span style="color: Tomato;">&gt;</span></strong> <strong>6 │ </strong> continue; <strong> │ </strong> <strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong><strong><span style="color: Tomato;">^</span></strong> <strong>7 │ </strong> &#125; <strong>8 │ </strong> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">The continue statement terminates execution of the statements in the current iteration, when used incorrectly it makes code less testable, less readable and less maintainable. Structured control flow statements such as if should be used instead.</span> <strong><span style="color: lightgreen;">ℹ</span></strong> <span style="color: lightgreen;">This rule belongs to the nursery group, which means it is not yet stable and may change in the future. Visit </span><span style="color: lightgreen;"><a href="https://biomejs.dev/linter/#nursery">https://biomejs.dev/linter/#nursery</a></span><span style="color: lightgreen;"> for more information.</span> </code></pre>

Valid

js
let sum = 0,
    i;

for(i = 0; i < 10; i++) {
    if(i < 5) {
        sum += i;
    }
}
</TabItem> </Tabs>