@@ -21,26 +21,12 @@ module.exports = function(context) {
21
21
var MISSING_MESSAGE = 'Component definition is missing display name' ;
22
22
var MISSING_MESSAGE_NAMED_COMP = '{{component}} component definition is missing display name' ;
23
23
24
- /**
25
- * Checks if the component must be validated
26
- * @param {Object } component The component to process
27
- * @returns {Boolean } True if the component must be validated, false if not.
28
- */
29
- function mustBeValidated ( component ) {
30
- return (
31
- component &&
32
- component . isReactComponent &&
33
- ! component . hasDisplayName
34
- ) ;
35
- }
36
-
37
24
/**
38
25
* Checks if we are declaring a display name
39
26
* @param {ASTNode } node The AST node being checked.
40
27
* @returns {Boolean } True if we are declaring a display name, false if not.
41
28
*/
42
29
function isDisplayNameDeclaration ( node ) {
43
-
44
30
// Special case for class properties
45
31
// (babel-eslint does not expose property name so we have to rely on tokens)
46
32
if ( node . type === 'ClassProperty' ) {
@@ -126,7 +112,6 @@ module.exports = function(context) {
126
112
if ( ! isDisplayNameDeclaration ( node ) ) {
127
113
return ;
128
114
}
129
-
130
115
markDisplayNameAsDeclared ( node ) ;
131
116
} ,
132
117
@@ -149,57 +134,39 @@ module.exports = function(context) {
149
134
} ,
150
135
151
136
ClassDeclaration : function ( node ) {
137
+ componentList . set ( context , node ) ;
152
138
if ( ! acceptTranspilerName || ! hasTranspilerName ( node ) ) {
153
139
return ;
154
140
}
155
141
markDisplayNameAsDeclared ( node ) ;
156
142
} ,
157
143
158
144
ObjectExpression : function ( node ) {
159
- // Search for the displayName declaration
160
- node . properties . forEach ( function ( property ) {
161
- if ( ! property . key ) {
162
- return ;
163
- }
164
-
165
- if ( ! isDisplayNameDeclaration ( property . key ) ) {
166
- return ;
167
- }
168
- markDisplayNameAsDeclared ( node ) ;
169
- } ) ;
170
- // Has transpiler name
171
- if ( acceptTranspilerName && hasTranspilerName ( node ) ) {
172
- markDisplayNameAsDeclared ( node ) ;
173
- }
174
-
175
- if ( componentUtil . isComponentDefinition ( node ) ) {
176
- componentList . set ( context , node , {
177
- isReactComponent : true
145
+ componentList . set ( context , node ) ;
146
+ if ( ! acceptTranspilerName || ! hasTranspilerName ( node ) ) {
147
+ // Search for the displayName declaration
148
+ node . properties . forEach ( function ( property ) {
149
+ if ( ! property . key || ! isDisplayNameDeclaration ( property . key ) ) {
150
+ return ;
151
+ }
152
+ markDisplayNameAsDeclared ( node ) ;
178
153
} ) ;
154
+ return ;
179
155
}
156
+ markDisplayNameAsDeclared ( node ) ;
180
157
} ,
181
158
182
159
'Program:exit' : function ( ) {
183
160
var list = componentList . getList ( ) ;
184
- // Report missing display name for all classes
161
+ // Report missing display name for all components
185
162
for ( var component in list ) {
186
- if ( ! list . hasOwnProperty ( component ) || ! mustBeValidated ( list [ component ] ) ) {
163
+ if ( ! list . hasOwnProperty ( component ) || list [ component ] . hasDisplayName ) {
187
164
continue ;
188
165
}
189
166
reportMissingDisplayName ( list [ component ] ) ;
190
167
}
191
- } ,
192
-
193
- ReturnStatement : function ( node ) {
194
- if ( ! componentUtil . isReactComponent ( context , node ) ) {
195
- return ;
196
- }
197
- componentList . set ( context , node , {
198
- isReactComponent : true
199
- } ) ;
200
168
}
201
169
} ;
202
-
203
170
} ;
204
171
205
172
module . exports . schema = [ {
0 commit comments