@@ -64,7 +64,7 @@ function getSorter(order: OrderDirection) {
6464
6565 result *= multiplier
6666
67- // In case the paths are equal (result === 0), sort them by importKind
67+ // In case the paths are equal (result === 0), sort them by importKind.
6868 if ( ! result && multiplierImportKind ) {
6969 result =
7070 multiplierImportKind *
@@ -82,24 +82,20 @@ export function mutateRanksToAlphabetize(
8282 imported : ImportNodeObject [ ] ,
8383 alphabetizeOptions : OrderDirection ,
8484) {
85- let groupedByRanks : Record < number , ImportNodeObject [ ] > = groupBy (
86- imported ,
87- ( item : ImportNodeObject ) => item . rank ,
88- )
89-
85+ let groupedByRanks = groupBy ( imported , ( item ) => item . rank )
9086 let sorterFunction = getSorter ( alphabetizeOptions )
9187
92- // Sort group keys so that they can be iterated on in order
88+ // Sort group keys so that they can be iterated on in order.
9389 let groupRanks = Object . keys ( groupedByRanks ) . sort ( ( a , b ) => Number ( a ) - Number ( b ) )
9490
95- // Sort imports locally within their group
91+ // Sort imports locally within their group.
9692 for ( let groupRank of groupRanks ) {
9793 groupedByRanks [ groupRank ] . sort ( sorterFunction )
9894 }
9995
100- // Assign globally unique rank to each import
96+ // Assign a globally unique rank to each import.
10197 let newRank = 0
102- let alphabetizedRanks = groupRanks . reduce ( ( accumulator , groupRank ) => {
98+ let alphabetizedRanks = groupRanks . reduce < Record < string , number > > ( ( accumulator , groupRank ) => {
10399 for ( let importedItem of groupedByRanks [ groupRank ] ) {
104100 accumulator [ `${ importedItem . value } |${ importedItem . node . importKind } ` ] =
105101 Number . parseInt ( groupRank , 10 ) + newRank
@@ -109,10 +105,9 @@ export function mutateRanksToAlphabetize(
109105 return accumulator
110106 } , { } )
111107
112- // Mutate the original group-rank with alphabetized-rank
113- // eslint-disable-next-line unicorn/no-array-for-each
114- imported . forEach ( ( importedItem ) => {
108+ // Mutate the original group-rank with alphabetized-rank.
109+ for ( let importedItem of imported ) {
115110 importedItem . rank =
116111 alphabetizedRanks [ `${ importedItem . value } |${ importedItem . node . importKind } ` ]
117- } )
112+ }
118113}
0 commit comments