5
5
library linter.src.rules.type_annotate_public_apis;
6
6
7
7
import 'package:analyzer/src/generated/ast.dart' ;
8
- import 'package:linter/src/linter.dart' ;
9
8
import 'package:linter/src/ast.dart' ;
9
+ import 'package:linter/src/linter.dart' ;
10
10
11
11
const desc = r'Type annotate public APIs.' ;
12
12
@@ -61,10 +61,10 @@ class TypeAnnotatePublicApis extends LintRule {
61
61
}
62
62
63
63
class Visitor extends SimpleAstVisitor {
64
+ _VisitorHelper v;
64
65
final LintRule rule;
65
- _VisitoHelper v;
66
66
Visitor (this .rule) {
67
- v = new _VisitoHelper (rule);
67
+ v = new _VisitorHelper (rule);
68
68
}
69
69
70
70
@override
@@ -74,60 +74,60 @@ class Visitor extends SimpleAstVisitor {
74
74
}
75
75
}
76
76
77
- @override
78
- visitTopLevelVariableDeclaration (TopLevelVariableDeclaration node) {
79
- if (node.variables.type == null ) {
80
- node.variables.accept (v);
81
- }
82
- }
83
-
84
77
@override
85
78
visitFunctionDeclaration (FunctionDeclaration node) {
86
79
if (! isPrivate (node.name)) {
87
- if (node.returnType == null ) {
80
+ if (node.returnType == null && ! node.isSetter ) {
88
81
rule.reportLint (node.name);
89
82
} else {
90
- node.functionExpression.parameters.accept (v);
83
+ node.functionExpression.parameters? .accept (v);
91
84
}
92
85
}
93
86
}
94
87
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
+
95
97
@override
96
98
visitMethodDeclaration (MethodDeclaration node) {
97
99
if (! isPrivate (node.name)) {
98
- if (node.returnType == null ) {
100
+ if (node.returnType == null && ! node.isSetter ) {
99
101
rule.reportLint (node.name);
100
102
} else {
101
- node.parameters.accept (v);
103
+ node.parameters? .accept (v);
102
104
}
103
105
}
104
106
}
105
107
106
108
@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);
112
112
}
113
113
}
114
114
}
115
115
116
- class _VisitoHelper extends RecursiveAstVisitor {
116
+ class _VisitorHelper extends RecursiveAstVisitor {
117
117
final LintRule rule;
118
- _VisitoHelper (this .rule);
118
+ _VisitorHelper (this .rule);
119
119
120
120
@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 );
124
124
}
125
125
}
126
126
127
127
@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 );
131
131
}
132
132
}
133
133
}
0 commit comments