The cascade operator should only be used if you are performing a sequence of operations on the same object. If you are only performing one operator, you should use . instead of ...
Kind
Enforces general style advice to avoid unnecessary code.
serviceManager.appState.setPausedOnBreakpoint(false);
var myAppState = serviceManager.appState..setPausedOnBreakpoint(false); // Here the cascade served a purpose.
[ ] List any existing rules this proposal modifies, complements, overlaps or conflicts with.
[ ] List any relevant issues (reported here, the SDK Tracker, or elsewhere).
[ ] If there's any prior art (e.g., in other linters), please add references here.
[ ] If this proposal corresponds to Effective Dart or Flutter Style Guide advice, please call it out. (If there isn't any corresponding advice, should there be?)
[x] If this proposal is motivated by real-world examples, please provide as many details as you can. Demonstrating potential impact is especially valuable.
unneccessary_cascade
Description
..
was used where.
would have the same effect.Details
The cascade operator should only be used if you are performing a sequence of operations on the same object. If you are only performing one operator, you should use
.
instead of..
.Kind
Enforces general style advice to avoid unnecessary code.
Bad Examples
Good Examples
Discussion
This lint is mostly useful to avoid issues sometimes only caught in code review when refactoring code that used a cascade. Example: https://github.com/flutter/devtools/pull/5004/files#r1061936361
Discussion checklist