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);