@@ -46,6 +46,7 @@ module.exports = Components.detect(function(context, components) {
46
46
47
47
var methodsOrder = getMethodsOrder ( {
48
48
order : [
49
+ 'static-methods' ,
49
50
'lifecycle' ,
50
51
'everything-else' ,
51
52
'render'
@@ -83,7 +84,7 @@ module.exports = Components.detect(function(context, components) {
83
84
84
85
/**
85
86
* Get indexes of the matching patterns in methods order configuration
86
- * @param {String } method - Method name .
87
+ * @param {Object } method - Method metadata .
87
88
* @returns {Array } The matching patterns indexes. Return [Infinity] if there is no match.
88
89
*/
89
90
function getRefPropIndexes ( method ) {
@@ -92,15 +93,29 @@ module.exports = Components.detect(function(context, components) {
92
93
var i ;
93
94
var j ;
94
95
var indexes = [ ] ;
95
- for ( i = 0 , j = methodsOrder . length ; i < j ; i ++ ) {
96
- isRegExp = methodsOrder [ i ] . match ( regExpRegExp ) ;
97
- if ( isRegExp ) {
98
- matching = new RegExp ( isRegExp [ 1 ] , isRegExp [ 2 ] ) . test ( method ) ;
99
- } else {
100
- matching = methodsOrder [ i ] === method ;
96
+
97
+ if ( method . static ) {
98
+ for ( i = 0 , j = methodsOrder . length ; i < j ; i ++ ) {
99
+ if ( methodsOrder [ i ] === 'static-methods' ) {
100
+ indexes . push ( i ) ;
101
+ break ;
102
+ }
101
103
}
102
- if ( matching ) {
103
- indexes . push ( i ) ;
104
+ }
105
+
106
+ // Either this is not a static method or static methods are not specified
107
+ // in the methodsOrder.
108
+ if ( indexes . length === 0 ) {
109
+ for ( i = 0 , j = methodsOrder . length ; i < j ; i ++ ) {
110
+ isRegExp = methodsOrder [ i ] . match ( regExpRegExp ) ;
111
+ if ( isRegExp ) {
112
+ matching = new RegExp ( isRegExp [ 1 ] , isRegExp [ 2 ] ) . test ( method . name ) ;
113
+ } else {
114
+ matching = methodsOrder [ i ] === method . name ;
115
+ }
116
+ if ( matching ) {
117
+ indexes . push ( i ) ;
118
+ }
104
119
}
105
120
}
106
121
@@ -109,6 +124,7 @@ module.exports = Components.detect(function(context, components) {
109
124
for ( i = 0 , j = methodsOrder . length ; i < j ; i ++ ) {
110
125
if ( methodsOrder [ i ] === 'everything-else' ) {
111
126
indexes . push ( i ) ;
127
+ break ;
112
128
}
113
129
}
114
130
}
@@ -127,7 +143,6 @@ module.exports = Components.detect(function(context, components) {
127
143
* @returns {String } Property name.
128
144
*/
129
145
function getPropertyName ( node ) {
130
-
131
146
// Special case for class properties
132
147
// (babel-eslint does not expose property name so we have to rely on tokens)
133
148
if ( node . type === 'ClassProperty' ) {
@@ -240,12 +255,12 @@ module.exports = Components.detect(function(context, components) {
240
255
241
256
/**
242
257
* Compare two properties and find out if they are in the right order
243
- * @param {Array } propertiesNames Array containing all the properties names .
244
- * @param {String } propA First property name.
245
- * @param {String } propB Second property name.
258
+ * @param {Array } propertiesInfos Array containing all the properties metadata .
259
+ * @param {Object } propA First property name and metadata
260
+ * @param {Object } propB Second property name.
246
261
* @returns {Object } Object containing a correct true/false flag and the correct indexes for the two properties.
247
262
*/
248
- function comparePropsOrder ( propertiesNames , propA , propB ) {
263
+ function comparePropsOrder ( propertiesInfos , propA , propB ) {
249
264
var i ;
250
265
var j ;
251
266
var k ;
@@ -258,8 +273,8 @@ module.exports = Components.detect(function(context, components) {
258
273
var refIndexesB = getRefPropIndexes ( propB ) ;
259
274
260
275
// Get current indexes for given properties
261
- var classIndexA = propertiesNames . indexOf ( propA ) ;
262
- var classIndexB = propertiesNames . indexOf ( propB ) ;
276
+ var classIndexA = propertiesInfos . indexOf ( propA ) ;
277
+ var classIndexB = propertiesInfos . indexOf ( propB ) ;
263
278
264
279
// Loop around the references indexes for the 1st property
265
280
for ( i = 0 , j = refIndexesA . length ; i < j ; i ++ ) {
@@ -300,7 +315,13 @@ module.exports = Components.detect(function(context, components) {
300
315
* @param {Array } properties Array containing all the properties.
301
316
*/
302
317
function checkPropsOrder ( properties ) {
303
- var propertiesNames = properties . map ( getPropertyName ) ;
318
+ var propertiesInfos = properties . map ( function ( node ) {
319
+ return {
320
+ name : getPropertyName ( node ) ,
321
+ static : node . static
322
+ } ;
323
+ } ) ;
324
+
304
325
var i ;
305
326
var j ;
306
327
var k ;
@@ -310,15 +331,15 @@ module.exports = Components.detect(function(context, components) {
310
331
var order ;
311
332
312
333
// Loop around the properties
313
- for ( i = 0 , j = propertiesNames . length ; i < j ; i ++ ) {
314
- propA = propertiesNames [ i ] ;
334
+ for ( i = 0 , j = propertiesInfos . length ; i < j ; i ++ ) {
335
+ propA = propertiesInfos [ i ] ;
315
336
316
337
// Loop around the properties a second time (for comparison)
317
- for ( k = 0 , l = propertiesNames . length ; k < l ; k ++ ) {
318
- propB = propertiesNames [ k ] ;
338
+ for ( k = 0 , l = propertiesInfos . length ; k < l ; k ++ ) {
339
+ propB = propertiesInfos [ k ] ;
319
340
320
341
// Compare the properties order
321
- order = comparePropsOrder ( propertiesNames , propA , propB ) ;
342
+ order = comparePropsOrder ( propertiesInfos , propA , propB ) ;
322
343
323
344
// Continue to next comparison is order is correct
324
345
if ( order . correct === true ) {
0 commit comments