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

Commit

Permalink
update to the current linter rule style
Browse files Browse the repository at this point in the history
  • Loading branch information
a14n committed Oct 21, 2018
1 parent 68ec3db commit 60814b8
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions lib/src/rules/avoid_shadowing.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,20 +54,19 @@ class B extends A {
```
''';

class AvoidShadowing extends LintRule {
_Visitor _visitor;

class AvoidShadowing extends LintRule implements NodeLintRule {
AvoidShadowing()
: super(
name: 'avoid_shadowing',
description: desc,
details: details,
group: Group.errors) {
_visitor = new _Visitor(this);
}
group: Group.errors);

@override
AstVisitor getVisitor() => _visitor;
void registerNodeProcessors(NodeLintRegistry registry) {
final visitor = new _Visitor(this);
registry.addVariableDeclarationStatement(this, visitor);
}
}

class _Visitor extends SimpleAstVisitor {
Expand All @@ -78,7 +77,7 @@ class _Visitor extends SimpleAstVisitor {
@override
visitVariableDeclarationStatement(VariableDeclarationStatement node) {
final variables = node.variables.variables.toList();
final library = variables.first.element.library;
final library = variables.first.declaredElement.library;

// exclude pattern : var name = this.name;
variables.removeWhere((variable) {
Expand Down Expand Up @@ -137,7 +136,8 @@ class _Visitor extends SimpleAstVisitor {
}) {
for (final variable in variables) {
final name = variable.name.name;
final getter = clazz.element.lookUpGetter(name, clazz.element.library);
final getter = clazz.declaredElement
.lookUpGetter(name, clazz.declaredElement.library);
if (getter != null && (!onlyStatics || getter.isStatic))
rule.reportLint(variable);
}
Expand All @@ -158,7 +158,7 @@ class _Visitor extends SimpleAstVisitor {
}

void _checkParameters(
FormalParameterList parameters, NodeList<VariableDeclaration> variables) {
FormalParameterList parameters, List<VariableDeclaration> variables) {
if (parameters == null) return;

final parameterNames =
Expand All @@ -172,8 +172,7 @@ class _Visitor extends SimpleAstVisitor {
}
}

void _checkParentBlock(
AstNode node, NodeList<VariableDeclaration> variables) {
void _checkParentBlock(AstNode node, List<VariableDeclaration> variables) {
final block = node.parent as Block;
final names = <String>[];
for (final statement in block.statements.takeWhile((n) => n != node)) {
Expand Down

0 comments on commit 60814b8

Please sign in to comment.