src/content/docs/linter/rules/use-while.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/complexity/useWhile`](/reference/diagnostics#diagnostic-category) - This rule isn't recommended, so you need to enable it. - This rule has a [**safe**](/linter/#safe-fixes) fix. - The default severity of this rule is [**warning**](/reference/diagnostics#warning). - Sources: - Same as [`sonarjs/prefer-while`](https://github.com/SonarSource/eslint-plugin-sonarjs/blob/HEAD/docs/rules/prefer-while.md){
"linter": {
"rules": {
"complexity": {
"useWhile": "error"
}
}
}
}
Enforce the use of while loops instead of for loops when the initializer and update expressions are not needed.
for (; x.running;) {
x.step();
}
for (let x = 0; x < 10; i++) {}
let x = 0
for (; x < 10; i++) {}
for (let x = 0; x < 10;) {
i++
}