跳到主要内容

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