File tree Expand file tree Collapse file tree 5 files changed +24
-70
lines changed Expand file tree Collapse file tree 5 files changed +24
-70
lines changed Original file line number Diff line number Diff line change @@ -25,28 +25,13 @@ module.exports = {
25
25
} ,
26
26
27
27
create : Components . detect ( ( context , components , utils ) => {
28
- /**
29
- * Get properties for a given AST node
30
- * @param {ASTNode } node The AST node being checked.
31
- * @returns {Array } Properties array.
32
- */
33
- function getComponentProperties ( node ) {
34
- switch ( node . type ) {
35
- case 'ClassExpression' :
36
- case 'ClassDeclaration' :
37
- return node . body . body ;
38
- default :
39
- return [ ] ;
40
- }
41
- }
42
-
43
28
/**
44
29
* Checks for shouldComponentUpdate property
45
30
* @param {ASTNode } node The AST node being checked.
46
31
* @returns {Boolean } Whether or not the property exists.
47
32
*/
48
33
function hasShouldComponentUpdate ( node ) {
49
- const properties = getComponentProperties ( node ) ;
34
+ const properties = astUtil . getComponentProperties ( node ) ;
50
35
return properties . some ( property => {
51
36
const name = astUtil . getPropertyName ( property ) ;
52
37
return name === 'shouldComponentUpdate' ;
Original file line number Diff line number Diff line change @@ -44,23 +44,6 @@ module.exports = {
44
44
// Public
45
45
// --------------------------------------------------------------------------
46
46
47
- /**
48
- * Get properties for a given AST node
49
- * @param {ASTNode } node The AST node being checked.
50
- * @returns {Array } Properties array.
51
- */
52
- function getComponentProperties ( node ) {
53
- switch ( node . type ) {
54
- case 'ClassExpression' :
55
- case 'ClassDeclaration' :
56
- return node . body . body ;
57
- case 'ObjectExpression' :
58
- return node . properties ;
59
- default :
60
- return [ ] ;
61
- }
62
- }
63
-
64
47
/**
65
48
* Checks whether a given array of statements is a single call of `super`.
66
49
* @see ESLint no-useless-constructor rule
@@ -195,7 +178,7 @@ module.exports = {
195
178
* @returns {Boolean } True if the node has at least one other property, false if not.
196
179
*/
197
180
function hasOtherProperties ( node ) {
198
- const properties = getComponentProperties ( node ) ;
181
+ const properties = astUtil . getComponentProperties ( node ) ;
199
182
return properties . some ( property => {
200
183
const name = astUtil . getPropertyName ( property ) ;
201
184
const isDisplayName = name === 'displayName' ;
Original file line number Diff line number Diff line change @@ -33,29 +33,13 @@ module.exports = {
33
33
} ) ;
34
34
}
35
35
36
- /**
37
- * Get properties for a given AST node
38
- * @param {ASTNode } node The AST node being checked.
39
- * @returns {Array } Properties array.
40
- */
41
- function getComponentProperties ( node ) {
42
- switch ( node . type ) {
43
- case 'ClassDeclaration' :
44
- return node . body . body ;
45
- case 'ObjectExpression' :
46
- return node . properties ;
47
- default :
48
- return [ ] ;
49
- }
50
- }
51
-
52
36
/**
53
37
* Check if a given AST node has a render method
54
38
* @param {ASTNode } node The AST node being checked.
55
39
* @returns {Boolean } True if there is a render method, false if not
56
40
*/
57
41
function hasRenderMethod ( node ) {
58
- const properties = getComponentProperties ( node ) ;
42
+ const properties = astUtil . getComponentProperties ( node ) ;
59
43
for ( let i = 0 , j = properties . length ; i < j ; i ++ ) {
60
44
if ( astUtil . getPropertyName ( properties [ i ] ) !== 'render' || ! properties [ i ] . value ) {
61
45
continue ;
Original file line number Diff line number Diff line change @@ -295,23 +295,6 @@ module.exports = {
295
295
}
296
296
}
297
297
298
- /**
299
- * Get properties for a given AST node
300
- * @param {ASTNode } node The AST node being checked.
301
- * @returns {Array } Properties array.
302
- */
303
- function getComponentProperties ( node ) {
304
- switch ( node . type ) {
305
- case 'ClassExpression' :
306
- case 'ClassDeclaration' :
307
- return node . body . body ;
308
- case 'ObjectExpression' :
309
- return node . properties . filter ( property => property . type === 'Property' ) ;
310
- default :
311
- return [ ] ;
312
- }
313
- }
314
-
315
298
/**
316
299
* Compare two properties and find out if they are in the right order
317
300
* @param {Array } propertiesInfos Array containing all the properties metadata.
@@ -424,7 +407,7 @@ module.exports = {
424
407
if ( ! has ( list , component ) ) {
425
408
continue ;
426
409
}
427
- const properties = getComponentProperties ( list [ component ] . node ) ;
410
+ const properties = astUtil . getComponentProperties ( list [ component ] . node ) ;
428
411
checkPropsOrder ( properties ) ;
429
412
}
430
413
Original file line number Diff line number Diff line change @@ -17,6 +17,25 @@ function getPropertyName(node) {
17
17
return '' ;
18
18
}
19
19
20
+ /**
21
+ * Get properties for a given AST node
22
+ * @param {ASTNode } node The AST node being checked.
23
+ * @returns {Array } Properties array.
24
+ */
25
+ function getComponentProperties ( node ) {
26
+ switch ( node . type ) {
27
+ case 'ClassDeclaration' :
28
+ case 'ClassExpression' :
29
+ return node . body . body ;
30
+ case 'ObjectExpression' :
31
+ // return node.properties;
32
+ return node . properties ;
33
+ default :
34
+ return [ ] ;
35
+ }
36
+ }
37
+
20
38
module . exports = {
21
- getPropertyName : getPropertyName
39
+ getPropertyName : getPropertyName ,
40
+ getComponentProperties : getComponentProperties
22
41
} ;
You can’t perform that action at this time.
0 commit comments