跳到主要內容

await_only_futures

穩定
核心
有可用的修復

僅等待 Future。

詳細資訊

#

避免對非 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

如果您使用 YAML 對映語法配置 linter 規則,請在 linter > rules 下新增 await_only_futures: true

analysis_options.yaml
yaml
linter:
  rules:
    await_only_futures: true