cascade_invocations
同じ参照に対する連続したメソッド呼び出しをカスケードします。
このルールは、Dart 2.0以降で使用できます。
このルールには、クイックフィックス があります。
詳細
#DO 同じ参照に対してメソッドを連続して呼び出す場合は、カスケードスタイルを使用してください。
悪い例
dart
SomeClass someReference = SomeClass();
someReference.firstMethod();
someReference.secondMethod();
悪い例
dart
SomeClass someReference = SomeClass();
...
someReference.firstMethod();
someReference.aProperty = value;
someReference.secondMethod();
良い例
dart
SomeClass someReference = SomeClass()
..firstMethod()
..aProperty = value
..secondMethod();
良い例
dart
SomeClass someReference = SomeClass();
...
someReference
..firstMethod()
..aProperty = value
..secondMethod();
使用方法
#cascade_invocations
ルールを有効にするには、analysis_options.yaml
ファイルのlinter > rules下にcascade_invocations
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- cascade_invocations
特に明記されていない限り、このサイトのドキュメントはDart 3.5.3を反映しています。ページは2024年7月3日に最終更新されました。 ソースを表示 または 問題を報告する。