Skip to content

Commit 07148b7

Browse files
pqCommit Queue
authored andcommitted
[element model] migrate use_setters_to_change_properties
Bug: https://github.com/dart-lang/linter/issues/5099 Change-Id: I456c6e950c745f5f41bfba5d131e991d2435f713 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394385 Reviewed-by: Brian Wilkerson <[email protected]> Commit-Queue: Phil Quitslund <[email protected]>
1 parent 0a238b3 commit 07148b7

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

pkg/linter/analyzer_use_new_elements.txt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,7 @@ lib/src/rules/prefer_initializing_formals.dart
1111
lib/src/rules/public_member_api_docs.dart
1212
lib/src/rules/unnecessary_overrides.dart
1313
lib/src/rules/use_build_context_synchronously.dart
14-
lib/src/rules/use_key_in_widget_constructors.dart
1514
lib/src/rules/use_late_for_private_fields_and_variables.dart
16-
lib/src/rules/use_setters_to_change_properties.dart
1715
lib/src/util/dart_type_utilities.dart
1816
lib/src/util/flutter_utils.dart
1917
lib/src/util/leak_detector_visitor.dart

pkg/linter/lib/src/extensions.dart

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,12 @@ extension ElementExtension on Element {
371371
}
372372

373373
extension ElementExtension2 on Element2? {
374+
Element2? get canonicalElement2 => switch (this) {
375+
GetterElement(:var variable3) => variable3,
376+
SetterElement(:var variable3) => variable3,
377+
_ => this,
378+
};
379+
374380
bool get isDartCorePrint {
375381
var self = this;
376382
return self is TopLevelFunctionElement &&

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

Lines changed: 6 additions & 5 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';
@@ -50,10 +50,11 @@ class _Visitor extends SimpleAstVisitor<void> {
5050
void checkExpression(Expression expression) {
5151
if (expression is AssignmentExpression &&
5252
expression.operator.type == TokenType.EQ) {
53-
var leftOperand = expression.writeElement?.canonicalElement;
54-
var rightOperand = expression.rightHandSide.canonicalElement;
55-
var parameterElement = node.declaredElement?.parameters.first;
56-
if (rightOperand == parameterElement && leftOperand is FieldElement) {
53+
var leftOperand = expression.writeElement2?.canonicalElement2;
54+
var rightOperand = expression.rightHandSide.canonicalElement2;
55+
var parameterElement =
56+
node.declaredFragment?.element.formalParameters.first;
57+
if (rightOperand == parameterElement && leftOperand is FieldElement2) {
5758
rule.reportLintForToken(node.name);
5859
}
5960
}

0 commit comments

Comments
 (0)