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

Commit 978780d

Browse files
committed
Fix NSME in type_annotate_public_apis (#151).
Improves getter/setter handling. Fixes #151. [email protected] Review URL: https://codereview.chromium.org//1496603002 .
1 parent 45829a6 commit 978780d

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

lib/src/rules/type_annotate_public_apis.dart

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,8 @@
55
library linter.src.rules.type_annotate_public_apis;
66

77
import 'package:analyzer/src/generated/ast.dart';
8-
import 'package:linter/src/linter.dart';
98
import 'package:linter/src/ast.dart';
9+
import 'package:linter/src/linter.dart';
1010

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

@@ -61,10 +61,10 @@ class TypeAnnotatePublicApis extends LintRule {
6161
}
6262

6363
class Visitor extends SimpleAstVisitor {
64+
_VisitorHelper v;
6465
final LintRule rule;
65-
_VisitoHelper v;
6666
Visitor(this.rule) {
67-
v = new _VisitoHelper(rule);
67+
v = new _VisitorHelper(rule);
6868
}
6969

7070
@override
@@ -74,60 +74,60 @@ class Visitor extends SimpleAstVisitor {
7474
}
7575
}
7676

77-
@override
78-
visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
79-
if (node.variables.type == null) {
80-
node.variables.accept(v);
81-
}
82-
}
83-
8477
@override
8578
visitFunctionDeclaration(FunctionDeclaration node) {
8679
if (!isPrivate(node.name)) {
87-
if (node.returnType == null) {
80+
if (node.returnType == null && !node.isSetter) {
8881
rule.reportLint(node.name);
8982
} else {
90-
node.functionExpression.parameters.accept(v);
83+
node.functionExpression.parameters?.accept(v);
9184
}
9285
}
9386
}
9487

88+
@override
89+
visitFunctionTypeAlias(FunctionTypeAlias node) {
90+
if (node.returnType == null) {
91+
rule.reportLint(node.name);
92+
} else {
93+
node.parameters.accept(v);
94+
}
95+
}
96+
9597
@override
9698
visitMethodDeclaration(MethodDeclaration node) {
9799
if (!isPrivate(node.name)) {
98-
if (node.returnType == null) {
100+
if (node.returnType == null && !node.isSetter) {
99101
rule.reportLint(node.name);
100102
} else {
101-
node.parameters.accept(v);
103+
node.parameters?.accept(v);
102104
}
103105
}
104106
}
105107

106108
@override
107-
visitFunctionTypeAlias(FunctionTypeAlias node) {
108-
if (node.returnType == null) {
109-
rule.reportLint(node.name);
110-
} else {
111-
node.parameters.accept(v);
109+
visitTopLevelVariableDeclaration(TopLevelVariableDeclaration node) {
110+
if (node.variables.type == null) {
111+
node.variables.accept(v);
112112
}
113113
}
114114
}
115115

116-
class _VisitoHelper extends RecursiveAstVisitor {
116+
class _VisitorHelper extends RecursiveAstVisitor {
117117
final LintRule rule;
118-
_VisitoHelper(this.rule);
118+
_VisitorHelper(this.rule);
119119

120120
@override
121-
visitVariableDeclaration(VariableDeclaration node) {
122-
if (!isPrivate(node.name)) {
123-
rule.reportLint(node.name);
121+
visitSimpleFormalParameter(SimpleFormalParameter param) {
122+
if (param.type == null) {
123+
rule.reportLint(param);
124124
}
125125
}
126126

127127
@override
128-
visitSimpleFormalParameter(SimpleFormalParameter param) {
129-
if (param.type == null) {
130-
rule.reportLint(param);
128+
visitVariableDeclaration(VariableDeclaration node) {
129+
if (!isPrivate(node.name)) {
130+
rule.reportLint(node.name);
131131
}
132132
}
133133
}

test/rules/type_annotate_public_apis.dart

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ typedef Foo(x); //LINT
1212

1313
typedef void Bar(int x);
1414

15+
int get xxx => 42; //OK: #151
16+
17+
get xxxx => 42; //LINT
18+
19+
set x(x) { } //LINT
20+
21+
set xx(int x) { } //OK
22+
1523
_f() {}
1624
const _X = '';
1725

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

33+
int get xxx => 42; //OK: #151
34+
35+
set xxxxx(x) { } //LINT
36+
37+
set xx(int x) { } //OK
38+
39+
get xxxx => 42; //LINT
40+
2541
var zzz, //LINT
2642
_zzz;
2743

0 commit comments

Comments
 (0)