Skip to content
This repository has been archived by the owner on Nov 20, 2024. It is now read-only.

Commit

Permalink
exclude pattern : var x = this.x;
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n committed Jan 24, 2018
1 parent cdbe9ce commit ca14554
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/src/rules/avoid_shadowing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,18 @@ class _Visitor extends SimpleAstVisitor {

@override
visitVariableDeclarationStatement(VariableDeclarationStatement node) {
final variables = node.variables.variables;
final variables = node.variables.variables.toList();
final library = variables.first.element.library;

// exclude pattern : var name = this.name;
variables.removeWhere((variable) {
final initializer = variable.initializer;
return initializer is PropertyAccess &&
initializer.propertyName.name == variable.name.name &&
(initializer.target is ThisExpression ||
initializer.target is SuperExpression);
});

bool skipInstanceMembers = false;
AstNode current = node;
while (current != null) {
Expand Down
13 changes: 13 additions & 0 deletions test/rules/avoid_shadowing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,17 @@ class E {
m(int x) {
int x; // LINT
}
}

// exclude pattern
class F {
int x;
m() {
var x = this.x; // OK
}
}
class F2 extends F {
m() {
var x = super.x; // OK
}
}

0 comments on commit ca14554

Please sign in to comment.