From 9f001a250dacd9155234689e3cf867dbab9eba3c Mon Sep 17 00:00:00 2001 From: Lucas Date: Fri, 14 Oct 2022 09:25:35 +0200 Subject: [PATCH] fix(avoid-passing-async-when-sync-expected): FutureOr Functions are interpreted as synchronous functions --- CHANGELOG.md | 4 ++++ .../avoid_passing_async_when_sync_expected/visitor.dart | 3 ++- .../examples/example.dart | 6 ++++++ 3 files changed, 12 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 66e6a44ff9..4b844527ba 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ # Changelog +## 4.21.2 + +* fix(avoid-passing-async-when-sync-expected): FutureOr Functions are interpreted as synchronous functions + ## 4.21.1 * fix: stop plugin flickering after migration to new api. diff --git a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/visitor.dart b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/visitor.dart index 35adf9713f..1a8f4a0942 100644 --- a/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/visitor.dart +++ b/lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/visitor.dart @@ -29,7 +29,8 @@ class _Visitor extends RecursiveAstVisitor { final parameterType = argument.staticParameterElement?.type; if (argumentType is FunctionType && parameterType is FunctionType) { if (argumentType.returnType.isDartAsyncFuture && - !parameterType.returnType.isDartAsyncFuture) { + (!parameterType.returnType.isDartAsyncFuture && + !parameterType.returnType.isDartAsyncFutureOr)) { _invalidArguments.add(argument); } } diff --git a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/examples/example.dart b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/examples/example.dart index 1a1f034823..5b1814e904 100644 --- a/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/examples/example.dart +++ b/test/src/analyzers/lint_analyzer/rules/rules_list/avoid_passing_async_when_sync_expected/examples/example.dart @@ -88,4 +88,10 @@ class _MyHomePageState extends State { ), ); } + + Future doSomeGetRequest() => Future.value(''); + + Future doAnotherGetRequest(String input) => Future.value(''); + + Future main() => doSomeGetRequest().then(doAnotherGetRequest); }