avoid-duplicate-cascades

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

example.dartdart
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';
}
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
1void f(dynamic value) {
2 value..name = 'first'..name = 'second';
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
2 value..name = 'first'..name = 'second';
3 value..count = 1..count = 1;
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
3 value..count = 1..count = 1;
4 value..[0] = 1..[0] = 2;
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
4 value..[0] = 1..[0] = 2;
5 value..child.name = 'a'..child.name = 'b';
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
5 value..child.name = 'a'..child.name = 'b';
6 value..name = 'a'..other = 'b'..name = 'c';
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
6 value..name = 'a'..other = 'b'..name = 'c';
7 value..[1 + 2] = 0..[1+2] = 1;
This cascade assigns to the same target more than once — remove the overwritten assignment or correct its target.
7 value..[1 + 2] = 0..[1+2] = 1;
8 value..child = value..child.name = 'a'..child.name = 'b';

Valid

example.dartdart
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.

falcon.jsonjson
{
  "linter": {
    "rules": {
      "correctness": {
        "avoid-duplicate-cascades": "error"
      }
    }
  }
}

Or silence one occurrence with a suppression comment; the reason is required.

example.dartdart
// falcon-ignore lint/correctness/avoid-duplicate-cascades: <reason>