@@ -57,32 +57,10 @@ module.exports = {
57
57
message,
58
58
data : { order : orderMsg . join ( ', ' ) } ,
59
59
fix ( fixer ) {
60
- const source = sourceCode . getText ( ) ;
61
- const last = properties [ properties . length - 1 ] ;
62
- // end loc to replace(including whitespaces).
63
- const finalEnd = sourceCode . getTokenAfter ( last , token => token . value === '}' && token . type === 'Punctuator' ) . range [ 0 ] ;
64
- // reorder the properties and put in result array.
65
- const result = [ ] ;
66
- for ( let j = 0 ; j < keyNames . length ; j ++ ) {
67
- const insertedIndex = orderMsg . indexOf ( keyNames [ j ] ) ;
68
- const propertyCode = sourceCode . getText ( properties [ j ] ) ;
69
- const propertyStart = properties [ j ] . range [ 1 ] ;
70
- const propertyEnd = j < properties . length - 1 ? properties [ j + 1 ] . range [ 0 ] : finalEnd ;
71
- let trailing = source . slice ( propertyStart , propertyEnd ) ;
72
-
73
- // for last property, should check & add trailling commas.
74
- if ( j === properties . length - 1 && sourceCode . getTokenAfter ( last ) . value !== ',' ) {
75
- trailing = ', ' + trailing ;
76
- }
77
- result [ insertedIndex ] = propertyCode + trailing ;
78
- }
79
-
80
- const start = properties [ 0 ] . range [ 0 ] ;
81
-
82
- return fixer . replaceTextRange (
83
- [ start , finalEnd ] ,
84
- result . join ( '' )
85
- ) ;
60
+ return orderMsg . map ( ( key , index ) => {
61
+ const propertyToInsert = test . properties [ keyNames . indexOf ( key ) ] ;
62
+ return fixer . replaceText ( test . properties [ index ] , sourceCode . getText ( propertyToInsert ) ) ;
63
+ } ) ;
86
64
} ,
87
65
} ) ;
88
66
}
0 commit comments