src/content/docs/linter/rules/use-valid-for-direction.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/correctness/useValidForDirection`](/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 [**error**](/reference/diagnostics#error). - Sources: - Same as [`for-direction`](https://eslint.org/docs/latest/rules/for-direction){
"linter": {
"rules": {
"correctness": {
"useValidForDirection": "error"
}
}
}
}
Enforce "for" loop update clause moving the counter in the right direction.
A for loop with a stop condition that can never be reached, such as one with a counter that moves in the wrong direction, will run infinitely. While there are occasions when an infinite loop is intended, the convention is to construct such loops as while loops. More typically, an infinite for loop is a bug.
for (var i = 0; i < 10; i--) {
}
for (var i = 10; i >= 0; i++) {
}
for (var i = 0; i > 10; i++) {
}
for (var i = 0; i < 10; i++) {
}