Skip to content

Commit

Permalink
Fix NSME in type_annotate_public_apis (#151).
Browse files Browse the repository at this point in the history
Improves getter/setter handling.

Fixes #151.

[email protected]

Review URL: https://codereview.chromium.org//1496603002 .
  • Loading branch information
pq committed Dec 2, 2015
1 parent 45829a6 commit 978780d
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 27 deletions.
54 changes: 27 additions & 27 deletions lib/src/rules/type_annotate_public_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
library linter.src.rules.type_annotate_public_apis;

import 'package:analyzer/src/generated/ast.dart';
import 'package:linter/src/linter.dart';
import 'package:linter/src/ast.dart';
import 'package:linter/src/linter.dart';

const desc = r'Type annotate public APIs.';

Expand Down Expand Up @@ -61,10 +61,10 @@ class TypeAnnotatePublicApis extends LintRule {
}

class Visitor extends SimpleAstVisitor {
_VisitorHelper v;
final LintRule rule;
_VisitoHelper v;
Visitor(this.rule) {
v = new _VisitoHelper(rule);
v = new _VisitorHelper(rule);
}

@override
Expand All @@ -74,60 +74,60 @@ class Visitor extends SimpleAstVisitor {
}
}

@override
visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
if (node.variables.type == null) {
node.variables.accept(v);
}
}

@override
visitFunctionDeclaration(FunctionDeclaration node) {
if (!isPrivate(node.name)) {
if (node.returnType == null) {
if (node.returnType == null && !node.isSetter) {
rule.reportLint(node.name);
} else {
node.functionExpression.parameters.accept(v);
node.functionExpression.parameters?.accept(v);
}
}
}

@override
visitFunctionTypeAlias(FunctionTypeAlias node) {
if (node.returnType == null) {
rule.reportLint(node.name);
} else {
node.parameters.accept(v);
}
}

@override
visitMethodDeclaration(MethodDeclaration node) {
if (!isPrivate(node.name)) {
if (node.returnType == null) {
if (node.returnType == null && !node.isSetter) {
rule.reportLint(node.name);
} else {
node.parameters.accept(v);
node.parameters?.accept(v);
}
}
}

@override
visitFunctionTypeAlias(FunctionTypeAlias node) {
if (node.returnType == null) {
rule.reportLint(node.name);
} else {
node.parameters.accept(v);
visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
if (node.variables.type == null) {
node.variables.accept(v);
}
}
}

class _VisitoHelper extends RecursiveAstVisitor {
class _VisitorHelper extends RecursiveAstVisitor {
final LintRule rule;
_VisitoHelper(this.rule);
_VisitorHelper(this.rule);

@override
visitVariableDeclaration(VariableDeclaration node) {
if (!isPrivate(node.name)) {
rule.reportLint(node.name);
visitSimpleFormalParameter(SimpleFormalParameter param) {
if (param.type == null) {
rule.reportLint(param);
}
}

@override
visitSimpleFormalParameter(SimpleFormalParameter param) {
if (param.type == null) {
rule.reportLint(param);
visitVariableDeclaration(VariableDeclaration node) {
if (!isPrivate(node.name)) {
rule.reportLint(node.name);
}
}
}
16 changes: 16 additions & 0 deletions test/rules/type_annotate_public_apis.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ typedef Foo(x); //LINT

typedef void Bar(int x);

int get xxx => 42; //OK: #151

get xxxx => 42; //LINT

set x(x) { } //LINT

set xx(int x) { } //OK

_f() {}
const _X = '';

Expand All @@ -22,6 +30,14 @@ class A {
static const y = ''; //LINT
static final z = 3; //LINT

int get xxx => 42; //OK: #151

set xxxxx(x) { } //LINT

set xx(int x) { } //OK

get xxxx => 42; //LINT

var zzz, //LINT
_zzz;

Expand Down

0 comments on commit 978780d

Please sign in to comment.