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, and this page is available as Markdown at https://rslint.rs/rules/eslint/for-direction.md.
close

for-direction

Added in v0.1.14

Configuration

PresetConfigured Value
✅ js.configs.recommended"error"
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:

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:

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

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

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

Original Documentation