diff --git a/lib/src/rules/avoid_shadowing.dart b/lib/src/rules/avoid_shadowing.dart index 424eafbc5..7ee0adb73 100644 --- a/lib/src/rules/avoid_shadowing.dart +++ b/lib/src/rules/avoid_shadowing.dart @@ -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) { diff --git a/test/rules/avoid_shadowing.dart b/test/rules/avoid_shadowing.dart index 95fcac607..12dbeb0ac 100644 --- a/test/rules/avoid_shadowing.dart +++ b/test/rules/avoid_shadowing.dart @@ -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 + } } \ No newline at end of file