Skip to main content

avoid-returning-cascades

added in: 1.18.0
Pro+

Warns when a cascade expression is being returned from a function.

Returning cascade expressions can add additional confusion to the code reader as to what is actually being returned.

Example

❌ Bad:

class Cow {
void moo() {}
}

Cow getCow() {
return Cow..moo(); // LINT: Avoid returning cascade expressions. Try declaring a variable separately and returning it instead.
}

✅ Good:

Cow getAnotherCow() {
final cow = Cow();
cow.moo();

return cow;
}