prefer_asserts_with_message
メッセージ付きのアサートを推奨します。
このルールは Dart 2.3 以降で使用可能です。
詳細
#アサーションが失敗した場合、理由を理解するのが必ずしも簡単ではありません。assert
にメッセージを追加すると、開発者が AssertionError が発生した理由を理解するのに役立ちます。
悪い例
dart
f(a) {
assert(a != null);
}
class A {
A(a) : assert(a != null);
}
良い例
dart
f(a) {
assert(a != null, 'a must not be null');
}
class A {
A(a) : assert(a != null, 'a must not be null');
}
使用法
#prefer_asserts_with_message
ルールを有効にするには、analysis_options.yaml
ファイルの linter > rules の下に prefer_asserts_with_message
を追加します。
analysis_options.yaml
yaml
linter:
rules:
- prefer_asserts_with_message
特に明記されていない限り、このサイトのドキュメントは Dart 3.5.3 を反映しています。最終更新日は 2024-07-03 です。 ソースを表示 または 問題を報告。