cascade_invocations
Cascade consecutive method invocations on the same reference.
This rule is available as of Dart 2.0.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
除非另有说明,文档之所提及适用于 Dart 3.5.0 版本,本页面最后更新时间: 2024-09-22。 查看文档源码 或者 报告页面问题。