const repeated inside an expression that is already constant

ID

dart.correctness.const_modifier_redundant

Severity

info

Remediation Complexity

trivial

Remediation Risk

low

Remediation Effort

low

Resource

Idiom

Language

Dart

Description

Reports a const keyword on an expression that already sits in a constant context - the initialiser of a const variable or field, or an argument of an enclosing const constructor call - where the keyword adds nothing.

Rationale

A constant context makes every nested expression constant, so the repeated keyword changes no behaviour and only adds noise. The cost is that it stops carrying information: once const appears in places where it is implied, a reader can no longer take its presence as a statement that this particular expression had to be canonicalised, and its absence stops standing out in the places where it does matter. Removing the redundant occurrences is what keeps the remaining ones readable.

The following code illustrates the pattern detected by this rule:

class Point {
  final int x;
  const Point(this.x);
}

// FLAGGED: const repeated inside an expression that is already constant
const origin = const Point(0);

Remediation

Delete the inner const. Keep the outermost one, the one that establishes the constant context, and let the nested expressions inherit it.

Configuration

This detector does not need any configuration.

© 2026 Xygeni. All rights reserved