avoid_duplicate_cascades
v0.4.0 Warning Fix Control Flow
Warns when a cascade expression contains duplicate sections — identical property assignments, method calls, or index operations repeated with the same arguments. Duplicate cascades are usually the result of a copy-paste error.
Why use this rule
Section titled “Why use this rule”When the same cascade section appears twice (e.g., ..name = 'test' repeated), the second one overwrites the first with the same value, making it redundant. For method calls, the duplicate invocation may cause unintended side effects. Either way, it signals a copy-paste mistake that should be fixed.
See also: Cascade notation
void bad() { // Same property assigned with same value twice final config = Config() ..name = 'test' ..name = 'test';
// Same method called twice final config2 = Config() ..reset() ..reset();
// Same index assigned with same value twice final list = [1, 2, 3] ..[1] = 5 ..[1] = 5;}void good() { // Different properties final config = Config() ..name = 'test' ..value = 42;
// Same property but different values final config2 = Config() ..name = 'first' ..name = 'second';
// Different indices final list = [1, 2, 3] ..[0] = 10 ..[1] = 20;}Configuration
Section titled “Configuration”This rule is in the core preset, so it is on with preset: core,
preset: recommended or preset: opinionated.
To turn it off:
rules: avoid_duplicate_cascades: falseTo keep the rule on but skip certain paths, use per-rule exclude.
Related rules
Section titled “Related rules”avoid_cascade_after_if_null— Detect cascades after if-null operators without parentheses.avoid_collapsible_if— Merge nested if statements with &&.avoid_constant_conditions— Detect comparisons where both sides are constants.avoid_constant_switches— Detect switch statements on constant expressions.