Skip to content

Commit 87d24d3

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate avoid_positional_boolean_parameters
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I8cd6c94e8ca053378117fd59ba44cd54587645d9 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/390540 Commit-Queue: Phil Quitslund <[email protected]> Auto-Submit: Phil Quitslund <[email protected]> Reviewed-by: Brian Wilkerson <[email protected]>
1 parent a505205 commit 87d24d3

File tree

1 file changed

+18
-11
lines changed

1 file changed

+18
-11
lines changed

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

Lines changed: 18 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +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/element.dart';
7+
import 'package:analyzer/dart/element/element2.dart';
88
import 'package:analyzer/dart/element/type.dart';
99
import 'package:collection/collection.dart';
1010

@@ -52,7 +52,7 @@ class _Visitor extends SimpleAstVisitor<void> {
5252
// Don't lint augmentations.
5353
if (node.isAugmentation) return;
5454

55-
var declaredElement = node.declaredElement;
55+
var declaredElement = node.declaredFragment?.element;
5656
if (declaredElement != null && !declaredElement.isPrivate) {
5757
checkParams(node.parameters.parameters);
5858
}
@@ -63,8 +63,8 @@ class _Visitor extends SimpleAstVisitor<void> {
6363
// Don't lint augmentations.
6464
if (node.isAugmentation) return;
6565

66-
var declaredElement = node.declaredElement;
67-
if (declaredElement != null && !declaredElement.isPrivate) {
66+
var element = node.element;
67+
if (element != null && !element.isPrivate) {
6868
checkParams(node.functionExpression.parameters?.parameters);
6969
}
7070
}
@@ -79,7 +79,7 @@ class _Visitor extends SimpleAstVisitor<void> {
7979
// Don't lint augmentations.
8080
if (node.isAugmentation) return;
8181

82-
var declaredElement = node.declaredElement;
82+
var declaredElement = node.declaredFragment?.element;
8383
if (declaredElement != null &&
8484
!node.isSetter &&
8585
!declaredElement.isPrivate &&
@@ -90,21 +90,28 @@ class _Visitor extends SimpleAstVisitor<void> {
9090
}
9191
}
9292

93-
bool _isOverridingMember(Element member) {
94-
var classElement = member.thisOrAncestorOfType<ClassElement>();
93+
bool _isOverridingMember(Element2 member) {
94+
var classElement = member.thisOrAncestorOfType2<ClassElement2>();
9595
if (classElement == null) return false;
9696

97-
var name = member.name;
97+
var name = member.name3;
9898
if (name == null) return false;
9999

100-
var libraryUri = classElement.library.source.uri;
100+
var libraryUri = classElement.library2.firstFragment.source.uri;
101101
return context.inheritanceManager
102-
.getInherited(classElement.thisType, Name(libraryUri, name)) !=
102+
.getInherited3(classElement.thisType, Name(libraryUri, name)) !=
103103
null;
104104
}
105105

106106
static bool _isBoolean(FormalParameter node) {
107-
var type = node.declaredElement?.type;
107+
var type = node.declaredFragment?.element.type;
108108
return !node.isNamed && type is InterfaceType && type.isDartCoreBool;
109109
}
110110
}
111+
112+
// TODO(pq): consider moving to `extensions.dart`
113+
extension on FunctionDeclaration {
114+
ExecutableElement2? get element =>
115+
// Check for a local function first.
116+
declaredElement2 ?? declaredFragment?.element;
117+
}

0 commit comments

Comments
 (0)