await_only_futures
僅等待 futures。
此規則自 Dart 2.0 起可用。
規則集:core、recommended、flutter
此規則有快速修正可用。
詳細資訊
#避免在非 future 的任何事物上使用 await。
允許在以下型別上使用 await:Future<X>
、FutureOr<X>
、Future<X>?
、FutureOr<X>?
和 dynamic
。
此外,特別允許使用 await null
作為引入微任務延遲的方式。
不良
dart
main() async {
print(await 23);
}
良好
dart
main() async {
await null; // If a delay is really intended.
print(23);
}
用法
#若要啟用 await_only_futures
規則,請在您的 analysis_options.yaml
檔案中的 linter > rules 下新增 await_only_futures
analysis_options.yaml
yaml
linter:
rules:
- await_only_futures
除非另有說明,否則本網站上的文件反映的是 Dart 3.6.0。頁面最後更新於 2024-07-03。 檢視原始碼或回報問題。