Skip to content

Commit 46475d1

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate avoid_returning_null_for_void
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I703e246e05738a9a42aa8bdaeae2c675486e6c5e Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/391842 Auto-Submit: Phil Quitslund <[email protected]> Commit-Queue: Phil Quitslund <[email protected]> Commit-Queue: Brian Wilkerson <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent 523ce0d commit 46475d1

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

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

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
import 'package:analyzer/dart/ast/ast.dart';
66
import 'package:analyzer/dart/ast/visitor.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
78
import 'package:analyzer/dart/element/type.dart';
89

910
import '../analyzer.dart';
@@ -50,22 +51,20 @@ class _Visitor extends SimpleAstVisitor<void> {
5051
}
5152

5253
void _visit(AstNode node, Expression expression) {
53-
if (expression is! NullLiteral) {
54-
return;
55-
}
54+
if (expression is! NullLiteral) return;
5655

5756
var parent = node.thisOrAncestorMatching(
5857
(e) => e is FunctionExpression || e is MethodDeclaration);
5958
if (parent == null) return;
6059

6160
var (type, isAsync, code) = switch (parent) {
6261
FunctionExpression() => (
63-
parent.declaredElement?.returnType,
62+
parent.element?.returnType,
6463
parent.body.isAsynchronous,
6564
LinterLintCode.avoid_returning_null_for_void_from_function,
6665
),
6766
MethodDeclaration() => (
68-
parent.declaredElement?.returnType,
67+
parent.declaredFragment?.element.returnType,
6968
parent.body.isAsynchronous,
7069
LinterLintCode.avoid_returning_null_for_void_from_method,
7170
),
@@ -82,3 +81,8 @@ class _Visitor extends SimpleAstVisitor<void> {
8281
}
8382
}
8483
}
84+
85+
extension on FunctionExpression {
86+
ExecutableElement2? get element =>
87+
declaredFragment?.element ?? declaredElement2;
88+
}

0 commit comments

Comments
 (0)