@@ -21,26 +21,12 @@ module.exports = function(context) {
2121 var MISSING_MESSAGE = 'Component definition is missing display name' ;
2222 var MISSING_MESSAGE_NAMED_COMP = '{{component}} component definition is missing display name' ;
2323
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-
3724 /**
3825 * Checks if we are declaring a display name
3926 * @param {ASTNode } node The AST node being checked.
4027 * @returns {Boolean } True if we are declaring a display name, false if not.
4128 */
4229 function isDisplayNameDeclaration ( node ) {
43-
4430 // Special case for class properties
4531 // (babel-eslint does not expose property name so we have to rely on tokens)
4632 if ( node . type === 'ClassProperty' ) {
@@ -126,7 +112,6 @@ module.exports = function(context) {
126112 if ( ! isDisplayNameDeclaration ( node ) ) {
127113 return ;
128114 }
129-
130115 markDisplayNameAsDeclared ( node ) ;
131116 } ,
132117
@@ -149,57 +134,39 @@ module.exports = function(context) {
149134 } ,
150135
151136 ClassDeclaration : function ( node ) {
137+ componentList . set ( context , node ) ;
152138 if ( ! acceptTranspilerName || ! hasTranspilerName ( node ) ) {
153139 return ;
154140 }
155141 markDisplayNameAsDeclared ( node ) ;
156142 } ,
157143
158144 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 ) ;
178153 } ) ;
154+ return ;
179155 }
156+ markDisplayNameAsDeclared ( node ) ;
180157 } ,
181158
182159 'Program:exit' : function ( ) {
183160 var list = componentList . getList ( ) ;
184- // Report missing display name for all classes
161+ // Report missing display name for all components
185162 for ( var component in list ) {
186- if ( ! list . hasOwnProperty ( component ) || ! mustBeValidated ( list [ component ] ) ) {
163+ if ( ! list . hasOwnProperty ( component ) || list [ component ] . hasDisplayName ) {
187164 continue ;
188165 }
189166 reportMissingDisplayName ( list [ component ] ) ;
190167 }
191- } ,
192-
193- ReturnStatement : function ( node ) {
194- if ( ! componentUtil . isReactComponent ( context , node ) ) {
195- return ;
196- }
197- componentList . set ( context , node , {
198- isReactComponent : true
199- } ) ;
200168 }
201169 } ;
202-
203170} ;
204171
205172module . exports . schema = [ {
0 commit comments