Rules / Style / avoid-single-cascade-in-expression-statements
avoid-single-cascade-in-expression-statements
Flags an expression statement that is a cascade with a single section.
A cascade (..) exists to chain several operations on one receiver; with a
single section it buys nothing over an ordinary member access and only
obscures intent. Rewrite foo..bar() as foo.bar(). Cascades with two or
more sections are the idiomatic form and are not flagged.
Invalid
example.dartdart
void f1(StringBuffer a) {
a..write('x');
}
void f2(List<int> list) {
list..add(1);
}
void f3(Foo b) {
b..field = 1;
}
void f4(List<int> c) {
c..[0] = 2;
}
void f5(Foo d) {
d..method();
}
void f6(StringBuffer e) {
e..clear();
}
Single cascade in an expression statement — use `.` instead of `..`
1void f1(StringBuffer a) {
2 a..write('x');
∙
Single cascade in an expression statement — use `.` instead of `..`
5void f2(List<int> list) {
6 list..add(1);
∙
Single cascade in an expression statement — use `.` instead of `..`
9void f3(Foo b) {
10 b..field = 1;
∙
Single cascade in an expression statement — use `.` instead of `..`
13void f4(List<int> c) {
14 c..[0] = 2;
∙
Single cascade in an expression statement — use `.` instead of `..`
17void f5(Foo d) {
18 d..method();
∙
Single cascade in an expression statement — use `.` instead of `..`
21void f6(StringBuffer e) {
22 e..clear();
∙
Valid
example.dartdart
void g1(StringBuffer a) {
a
..write('x')
..write('y');
}
void g2(List<int> list) {
list.add(1);
}
void g3(Foo b) {
final x = b..field = 1;
print(x);
}
Foo g4(Foo d) {
return d..method();
}
void g5(StringBuffer e) {
e
..clear()
..write('z');
}
void g6(Foo f) {
f.method();
}
How to configure
Set the severity of avoid-single-cascade-in-expression-statements in your falcon.json:
falcon.jsonjson
{
"linter": {
"rules": {
"style": {
"avoid-single-cascade-in-expression-statements": "error"
}
}
}
}