Skip to content

Commit

Permalink
[element model] migrate avoid_types_as_parameter_names
Browse files Browse the repository at this point in the history
Bug: https://github.com/dart-lang/linter/issues/5099
Change-Id: I279df798db88bec35276e5e0c66793da9d45fde0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394601
Reviewed-by: Brian Wilkerson <[email protected]>
Auto-Submit: Phil Quitslund <[email protected]>
Commit-Queue: Brian Wilkerson <[email protected]>
  • Loading branch information
pq authored and Commit Queue committed Nov 11, 2024
1 parent 9a76ff8 commit 0095085
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
16 changes: 8 additions & 8 deletions pkg/linter/lib/src/rules/avoid_types_as_parameter_names.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/token.dart';
import 'package:analyzer/dart/ast/visitor.dart';
import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
// ignore: implementation_imports
import 'package:analyzer/src/dart/element/extensions.dart';

Expand Down Expand Up @@ -50,10 +50,10 @@ class _Visitor extends SimpleAstVisitor<void> {
@override
void visitFormalParameterList(FormalParameterList node) {
for (var parameter in node.parameters) {
var declaredElement = parameter.declaredElement;
var declaredElement = parameter.declaredFragment?.element;
var name = parameter.name;
if (declaredElement != null &&
declaredElement is! FieldFormalParameterElement &&
declaredElement is! FieldFormalParameterElement2 &&
declaredElement.hasImplicitType &&
name != null &&
_isTypeName(node, name)) {
Expand All @@ -66,11 +66,11 @@ class _Visitor extends SimpleAstVisitor<void> {
var result =
resolveNameInScope(name.lexeme, scope, shouldResolveSetter: false);
if (result.isRequestedName) {
var element = result.element;
return element is ClassElement ||
element is ExtensionTypeElement ||
element is TypeAliasElement ||
(element is TypeParameterElement && !element.isWildcardVariable);
var element = result.element2;
return element is ClassElement2 ||
element is ExtensionTypeElement2 ||
element is TypeAliasElement2 ||
(element is TypeParameterElement2 && !element.isWildcardVariable);
}
return false;
}
Expand Down
6 changes: 6 additions & 0 deletions pkg/linter/lib/src/util/scope.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
// BSD-style license that can be found in the LICENSE file.

import 'package:analyzer/dart/element/element.dart';
import 'package:analyzer/dart/element/element2.dart';
import 'package:analyzer/dart/element/scope.dart';
// ignore: implementation_imports
import 'package:analyzer/src/dart/ast/ast.dart';
// ignore: implementation_imports
import 'package:analyzer/src/generated/resolver.dart' show ScopeResolverVisitor;
// ignore: implementation_imports
import 'package:analyzer/src/utilities/extensions/element.dart';

LinterNameInScopeResolutionResult resolveNameInScope(
String id,
Expand Down Expand Up @@ -57,6 +60,9 @@ class LinterNameInScopeResolutionResult {
const LinterNameInScopeResolutionResult._requestedName(this.element)
: _state = _LinterNameInScopeResolutionResultState.requestedName;

/// The element with the requested basename, `null` is [isNone].
Element2? get element2 => element.asElement2;

bool get isDifferentName =>
_state == _LinterNameInScopeResolutionResultState.differentName;

Expand Down

0 comments on commit 0095085

Please sign in to comment.