avoid-duplicate-cascades
- Group
- Correctness
- Path
lint/correctness/avoid-duplicate-cascades- Default
- Off, opt in
- Origin
- Falcon
- Rule
- 46 of 512
Flags repeated field or index assignment targets within one cascade. Calls are not assumed redundant. Different right-hand sides still overwrite the same target; calls, mutations, or replaced receiver paths prevent comparison.
Invalid
void f(dynamic value) {
value..name = 'first'..name = 'second';
value..count = 1..count = 1;
value..[0] = 1..[0] = 2;
value..child.name = 'a'..child.name = 'b';
value..name = 'a'..other = 'b'..name = 'c';
value..[1 + 2] = 0..[1+2] = 1;
value..child = value..child.name = 'a'..child.name = 'b';
}void f(dynamic value) { value..name = 'first'..name = 'second'; value..name = 'first'..name = 'second'; value..count = 1..count = 1; value..count = 1..count = 1; value..[0] = 1..[0] = 2; value..[0] = 1..[0] = 2; value..child.name = 'a'..child.name = 'b'; value..child.name = 'a'..child.name = 'b'; value..name = 'a'..other = 'b'..name = 'c'; value..name = 'a'..other = 'b'..name = 'c'; value..[1 + 2] = 0..[1+2] = 1; value..[1 + 2] = 0..[1+2] = 1; value..child = value..child.name = 'a'..child.name = 'b';Valid
void f(dynamic value, dynamic next) {
value..first = 1..second = 1;
value..[0] = 1..[1] = 1;
value..child.name = 'a'..other.name = 'a';
value..reset()..reset();
value..set(1)..set(2);
value..count += 1..count += 1;
value..[next()] = 1..[next()] = 2;
value..child().name = 1..child().name = 2;
}
void stateful(dynamic writer, dynamic value, int i) {
writer..indent = 2..writeln('x')..indent = 0;
value..[++i] = 1..[++i] = 2;
value..[--i] = 1..[--i] = 2;
}
void rhsMutations(List<int> xs) {
var i = 0;
xs..[i] = i++..[i] = 9;
xs..[i] = i--..[i] = 9;
xs..[i] = ++i..[i] = 9;
xs..[i] = --i..[i] = 9;
xs..[i] = (i = 1)..[i] = 9;
xs..[i] = (i += 1)..[i] = 9;
}
class Counter {
int i = 0;
void increment() => i++;
}
void nestedMutations(List<int> xs, Counter counter) {
xs..[counter.i] = (counter..i = 1).i..[counter.i] = 9;
xs..[counter.i] = (counter..increment()).i..[counter.i] = 9;
xs..[(counter..i += 1).i] = 1..[(counter..i += 1).i] = 2;
}
void replacedReceivers(dynamic value, dynamic other, int i) {
value..child.name = 'a'..child = other..child.name = 'b';
value..[i].name = 'a'..[i] = other..[i].name = 'b';
value..child[i].name = 'a'..child[i] = other..child[i].name = 'b';
value..child.name = 'a'..child += other..child.name = 'b';
value..[i].name = 'a'..[i] += other..[i].name = 'b';
value..[0].name = 'a'..[i] = other..[0].name = 'b';
value..child[0].name = 'a'..child[i] = other..child[0].name = 'b';
}Configure avoid-duplicate-cascades
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"correctness": {
"avoid-duplicate-cascades": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/correctness/avoid-duplicate-cascades: <reason>More correctness rules
- avoid-duplicate-collection-elements
Flags repeated scalar literals and stable local reads in list and set literals.
- avoid-duplicate-exports
Flags export directives whose visible names are already covered by another export.
- avoid-duplicate-factories
Flags factories in one type with the same implementation, ignoring factory names and alpha-renaming parameters by position.
- avoid-duplicate-initializers
Flags final/const variables with identical initializers in the same scope.
- avoid-duplicate-map-keysrecommended
Flags repeated literal keys in map literals, including literal spreads and collection
ifentries. - avoid-duplicate-mixins
Flags repeated mixins in a with clause or a same-library superclass chain.
- avoid-duplicate-named-imports
Flags imports of the same library that differ only in their name prefix.
- avoid-duplicate-switch-case-conditionsrecommended
Flags repeated
whenguards on syntactically identical switch patterns.