cascade_invocations
Cascade consecutive method invocations on the same reference.
This rule is available as of Dart 2.0.
This rule has a quick fix available.
Details
#DO Use the cascading style when successively invoking methods on the same reference.
BAD:
dart
SomeClass someReference = SomeClass();
someReference.firstMethod();
someReference.secondMethod();
BAD:
dart
SomeClass someReference = SomeClass();
...
someReference.firstMethod();
someReference.aProperty = value;
someReference.secondMethod();
GOOD:
dart
SomeClass someReference = SomeClass()
..firstMethod()
..aProperty = value
..secondMethod();
GOOD:
dart
SomeClass someReference = SomeClass();
...
someReference
..firstMethod()
..aProperty = value
..secondMethod();
Usage
#To enable the cascade_invocations
rule, add cascade_invocations
under linter > rules in your analysis_options.yaml
file:
analysis_options.yaml
yaml
linter:
rules:
- cascade_invocations
Unless stated otherwise, the documentation on this site reflects Dart 3.5.4. Page last updated on 2024-07-03. View source or report an issue.