Skip to content

Commit 5297291

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate avoid_void_async
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I9b7f68540c3a950ddd673da7eac04e9c2cdc1614 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390782 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 0833893 commit 5297291

File tree

3 files changed

+19
-13
lines changed

3 files changed

+19
-13
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
lib/src/ast.dart
22
lib/src/extensions.dart
33
lib/src/rules/avoid_setters_without_getters.dart
4-
lib/src/rules/avoid_void_async.dart
54
lib/src/rules/deprecated_member_use_from_same_package.dart
65
lib/src/rules/invalid_runtime_check_with_js_interop_types.dart
76
lib/src/rules/prefer_asserts_in_initializer_lists.dart

pkg/linter/lib/src/rules/avoid_void_async.dart

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/token.dart';
77
import 'package:analyzer/dart/ast/visitor.dart';
8-
import 'package:analyzer/dart/element/element.dart';
8+
import 'package:analyzer/dart/element/element2.dart';
99
import 'package:analyzer/dart/element/type.dart';
1010

1111
import '../analyzer.dart';
@@ -40,31 +40,27 @@ class _Visitor extends SimpleAstVisitor<void> {
4040
void visitFunctionDeclaration(FunctionDeclaration node) {
4141
if (node.name.lexeme == 'main' && node.parent is CompilationUnit) return;
4242
_check(
43-
declaredElement: node.declaredElement,
44-
returnType: node.returnType,
43+
fragment: node.declaredFragment,
4544
errorNode: node.name,
4645
);
4746
}
4847

4948
@override
5049
void visitMethodDeclaration(MethodDeclaration node) {
5150
_check(
52-
declaredElement: node.declaredElement,
53-
returnType: node.returnType,
51+
fragment: node.declaredFragment,
5452
errorNode: node.name,
5553
);
5654
}
5755

5856
void _check({
59-
required ExecutableElement? declaredElement,
60-
required TypeAnnotation? returnType,
57+
required ExecutableFragment? fragment,
6158
required Token errorNode,
6259
}) {
63-
if (declaredElement == null) return;
64-
if (declaredElement.isGenerator) return;
65-
if (!declaredElement.isAsynchronous) return;
66-
if (returnType == null) return;
67-
if (returnType.type is VoidType) {
60+
if (fragment == null) return;
61+
if (fragment.isGenerator) return;
62+
if (!fragment.isAsynchronous) return;
63+
if (fragment.element.returnType is VoidType) {
6864
rule.reportLintForToken(errorNode);
6965
}
7066
}

pkg/linter/test/rules/avoid_void_async_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,17 @@ void get f => null;
145145
''');
146146
}
147147

148+
test_localFunction_async() async {
149+
await assertDiagnostics(r'''
150+
Future<void> f() async {
151+
void g() async {}
152+
}
153+
''', [
154+
error(WarningCode.UNUSED_ELEMENT, 32, 1),
155+
lint(32, 1),
156+
]);
157+
}
158+
148159
test_main_async() async {
149160
await assertNoDiagnostics(r'''
150161
Future<void> f() async { }

0 commit comments

Comments
 (0)