Skip to content
This repository was archived by the owner on Jul 16, 2023. It is now read-only.

Commit 1369ced

Browse files
authored
fix: make avoid-redundant-async correctly handle nullable return values (#1009)
1 parent 9ac53f1 commit 1369ced

File tree

4 files changed

+9
-1
lines changed

4 files changed

+9
-1
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 4.19.1
44

5+
* fix: make [`avoid-redundant-async`](https://dartcodemetrics.dev/docs/rules/common/avoid-redundant-async) correctly handle nullable return values.
56
* fix: make [`avoid-wrapping-in-padding`](https://dartcodemetrics.dev/docs/rules/flutter/avoid-wrapping-in-padding) trigger only on Container widget.
67

78
## 4.19.0

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/avoid_redundant_async_rule.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import 'package:analyzer/dart/ast/ast.dart';
44
import 'package:analyzer/dart/ast/token.dart';
55
import 'package:analyzer/dart/ast/visitor.dart';
6+
import 'package:analyzer/dart/element/nullability_suffix.dart';
67

78
import '../../../../../utils/node_utils.dart';
89
import '../../../lint_utils.dart';

lib/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/visitor.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ class _AsyncVisitor extends RecursiveAstVisitor<void> {
5353

5454
final type = node.expression?.staticType;
5555

56-
if (type == null || !type.isDartAsyncFuture) {
56+
if (type == null ||
57+
!type.isDartAsyncFuture ||
58+
type.nullabilitySuffix == NullabilitySuffix.question) {
5759
hasValidAsync = true;
5860
}
5961
}

test/src/analyzers/lint_analyzer/rules/rules_list/avoid_redundant_async/examples/example.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,8 @@ class SomeClass {
3030

3131
print(records);
3232
}
33+
34+
Future<void> returnNullable(SomeClass? instance) async {
35+
return instance?.report([]);
36+
}
3337
}

0 commit comments

Comments
 (0)