discarded_futures
Don't invoke asynchronous functions in non-async
blocks.
此规则自 Dart 2.18 版本起可用。
此规则提供 快速修复 。
详情
#Making asynchronous calls in non-async
functions is usually the sign of a programming error. In general these functions should be marked async
and such futures should likely be awaited (as enforced by unawaited_futures
).
DON'T invoke asynchronous functions in non-async
blocks.
BAD:
dart
void recreateDir(String path) {
deleteDir(path);
createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
GOOD:
dart
Future<void> recreateDir(String path) async {
await deleteDir(path);
await createDir(path);
}
Future<void> deleteDir(String path) async {}
Future<void> createDir(String path) async {}
使用方法
#要启用 discarded_futures
规则,请在你的 analysis_options.yaml
文件中,在 linter > rules 下添加 discarded_futures
:
analysis_options.yaml
yaml
linter:
rules:
- discarded_futures
除非另有说明,否则本网站上的文档反映的是 Dart 3.6.0。页面最后更新于 2025-02-05。 查看源代码 或 报告问题.