close

for-direction

Configuration

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