跳到主要内容

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