if condition is built only from literals, so it is constant

ID

dart.correctness.literal_only_boolean

Severity

low

Remediation Complexity

medium

Remediation Risk

low

Remediation Effort

low

Resource

Suspicious Construct

Language

Dart

Description

Reports an if condition composed entirely of literals — true, false, a negation of either, a conjunction or disjunction of two boolean literals, or a comparison of two numeric literals — so its value is fixed at compile time.

Rationale

A condition that cannot vary is not a decision. One branch always runs and the other is dead, which means the code says something different from what it does: a reader takes the guard at face value, and a maintainer edits a branch that never executes. The usual origin is a switch left over from debugging or a bisection, so the constant is not intended to ship and nothing in the source marks it as temporary.

The following code illustrates the pattern detected by this rule:

class FeatureGate {
  void render(String body) {
    // FLAGGED: if condition is built only from literals, so it is constant
    if (true) {
      emit(body);
    }
  }

  void emit(String body) {}
}

Remediation

Replace the literal with the condition it stands in for, or remove the if and keep only the branch that runs. When a feature really is toggled at build time, put the flag behind a named constant so the intent is explicit and the toggle is greppable.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved