6
6
'use strict' ;
7
7
8
8
const has = require ( 'has' ) ;
9
-
9
+ const entries = require ( 'object.entries' ) ;
10
10
const arrayIncludes = require ( 'array-includes' ) ;
11
+
11
12
const Components = require ( '../util/Components' ) ;
12
13
const astUtil = require ( '../util/ast' ) ;
13
14
const docsUrl = require ( '../util/docsUrl' ) ;
@@ -298,19 +299,11 @@ module.exports = {
298
299
function reportErrors ( ) {
299
300
dedupeErrors ( ) ;
300
301
301
- let nodeA ;
302
- let nodeB ;
303
- let indexA ;
304
- let indexB ;
305
- for ( const i in errors ) {
306
- if ( ! has ( errors , i ) ) {
307
- continue ;
308
- }
309
-
310
- nodeA = errors [ i ] . node ;
311
- nodeB = errors [ i ] . closest . ref . node ;
312
- indexA = i ;
313
- indexB = errors [ i ] . closest . ref . index ;
302
+ entries ( errors ) . forEach ( ( entry ) => {
303
+ const nodeA = entry [ 1 ] . node ;
304
+ const nodeB = entry [ 1 ] . closest . ref . node ;
305
+ const indexA = entry [ 0 ] ;
306
+ const indexB = entry [ 1 ] . closest . ref . index ;
314
307
315
308
context . report ( {
316
309
node : nodeA ,
@@ -321,7 +314,7 @@ module.exports = {
321
314
position : indexA < indexB ? 'before' : 'after'
322
315
}
323
316
} ) ;
324
- }
317
+ } ) ;
325
318
}
326
319
327
320
/**
@@ -400,44 +393,29 @@ module.exports = {
400
393
typeAnnotation : ! ! node . typeAnnotation && node . value === null
401
394
} ) ) ;
402
395
403
- let i ;
404
- let j ;
405
- let k ;
406
- let l ;
407
- let propA ;
408
- let propB ;
409
- let order ;
410
-
411
396
// Loop around the properties
412
- for ( i = 0 , j = propertiesInfos . length ; i < j ; i ++ ) {
413
- propA = propertiesInfos [ i ] ;
414
-
397
+ propertiesInfos . forEach ( ( propA , i ) => {
415
398
// Loop around the properties a second time (for comparison)
416
- for ( k = 0 , l = propertiesInfos . length ; k < l ; k ++ ) {
399
+ propertiesInfos . forEach ( ( propB , k ) => {
417
400
if ( i === k ) {
418
- continue ;
401
+ return ;
419
402
}
420
403
421
- propB = propertiesInfos [ k ] ;
422
-
423
404
// Compare the properties order
424
- order = comparePropsOrder ( propertiesInfos , propA , propB ) ;
425
-
426
- // Continue to next comparison is order is correct
427
- if ( order . correct === true ) {
428
- continue ;
405
+ const order = comparePropsOrder ( propertiesInfos , propA , propB ) ;
406
+
407
+ if ( ! order . correct ) {
408
+ // Store an error if the order is incorrect
409
+ storeError ( {
410
+ node : properties [ i ] ,
411
+ index : order . indexA
412
+ } , {
413
+ node : properties [ k ] ,
414
+ index : order . indexB
415
+ } ) ;
429
416
}
430
-
431
- // Store an error if the order is incorrect
432
- storeError ( {
433
- node : properties [ i ] ,
434
- index : order . indexA
435
- } , {
436
- node : properties [ k ] ,
437
- index : order . indexB
438
- } ) ;
439
- }
440
- }
417
+ } ) ;
418
+ } ) ;
441
419
}
442
420
443
421
return {
0 commit comments