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/no-constant-condition.md.
close

no-constant-condition

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: {
      'no-constant-condition': 'error',
    },
  },
]);

Rule Details

Disallows constant expressions in conditions of if, while, do-while, for statements, and ternary expressions. A constant condition is one that always evaluates to the same truthy or falsy value, such as a literal, an always-truthy expression like an object literal, or a compile-time computable expression. This usually indicates a programmer error.

By default, while (true) loops are allowed (via the "allExceptWhileTrue" option) since they are a common pattern for intentional infinite loops with a break inside.

Examples of incorrect code for this rule:

if (true) {
}

if ('hello') {
}

while (1) {}

for (; false; ) {}

var result = 0 ? a : b;

Examples of correct code for this rule:

if (x === 0) {
}

while (true) {} // allowed by default

while (condition) {}

for (; i < 10; i++) {}

var result = x ? a : b;

Original Documentation