> For AI agents: the complete documentation index is available at https://rslint.rs/llms.txt, the full documentation bundle is available at https://rslint.rs/llms-full.txt.

# for-direction

[Added in v0.1.14](https://github.com/web-infra-dev/rslint/releases/tag/v0.1.14)
## Configuration

| Preset                   | Configured Value |
| ------------------------ | ---------------- |
| ✅ js.configs.recommended | `"error"`        |


```ts title=rslint.config.ts
import { defineConfig, js } from '@rslint/core';

export default defineConfig([
  js.configs.recommended,
  {
    rules: {
      'for-direction': 'error',
    },
  },
]);
```

## Rule Details

Enforces that the update clause in a `for` loop moves the counter variable in the correct direction relative to the loop's stop condition. A `for` loop with a counter that moves in the wrong direction will run infinitely.

Examples of **incorrect** code for this rule:

```javascript
for (var i = 0; i < 10; i--) {}

for (var i = 10; i >= 0; i++) {}

for (var i = 0; i < 10; i -= 1) {}
```

Examples of **correct** code for this rule:

```javascript
for (var i = 0; i < 10; i++) {}

for (var i = 10; i >= 0; i--) {}

for (var i = 0; i < 10; i += 1) {}
```

## Original Documentation

- [ESLint: for-direction](https://eslint.org/docs/latest/rules/for-direction)
- [Source code](https://github.com/eslint/eslint/blob/v10.8.1/lib/rules/for-direction.js)
