avoid-single-cascade-in-expression-statements
Same as avoid_single_cascade_in_expression_statements in Dart lints
- Group
- Style
- Path
lint/style/avoid-single-cascade-in-expression-statements- Default
- On (recommended)
- Origin
- Dart lints
- Rule
- 140 of 512
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
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();
}
// Closure argument of a constructor invocation (`Expr::New`).
Widget f7(StringBuffer a) {
return new ElevatedButton(onPressed: () {
a..write('x');
});
}
// Closure nested inside a collection literal.
List<VoidCallback> f8(StringBuffer a) {
return [
() {
a..clear();
},
];
}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(); return new ElevatedButton(onPressed: () { a..write('x'); () { a..clear();Valid
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();
}Configure avoid-single-cascade-in-expression-statements
Set its severity in falcon.json. See the configuration guide.
{
"linter": {
"rules": {
"style": {
"avoid-single-cascade-in-expression-statements": "error"
}
}
}
}Or silence one occurrence with a suppression comment; the reason is required.
// falcon-ignore lint/style/avoid-single-cascade-in-expression-statements: <reason>More style rules
- avoid-single-child-column-or-row
avoid_single_child_column_or_rowflutterFlags a
Column,Row, orFlexwidget built with a single child. - avoid-top-level-member-access
Flags mutable global state: non-
const, non-finaltop-level variables and static fields, plus every read of mutable top-level variables. - avoid-types-on-closure-parameters
avoid_types_on_closure_parametersFlags type annotations on closure parameters whose types come from context.
- avoid-unnecessary-block
Flags standalone nested blocks that introduce no lexical declarations.
- avoid-unnecessary-call
Prefer direct invocation of functions and resolved callable instances.
- avoid-unnecessary-continue
Flags an unlabeled continue at the end of a loop body or its final branch.
- avoid-unnecessary-getter
Flags a getter that only exposes a private final field.
- avoid-unnecessary-if
Flags an if branch that only returns the same expression as the following return.