@@ -242,10 +242,18 @@ function makeOutOfOrderReport(context, imported) {
242
242
reportOutOfOrder ( context , imported , outOfOrder , 'before' ) ;
243
243
}
244
244
245
- function getSorter ( ascending ) {
246
- const multiplier = ascending ? 1 : - 1 ;
245
+ function getSorter ( ascending , caseInsensitive ) {
246
+ const multiplier = ( ascending ? 1 : - 1 ) ;
247
+ const collate = caseInsensitive
248
+ ? caseInsensitive === 'invert'
249
+ ? swapCase
250
+ : ( s ) => String ( s ) . toLowerCase ( )
251
+ : ( s ) => s ;
247
252
248
253
return function importsSorter ( importA , importB ) {
254
+ importA = collate ( importA ) ;
255
+ importB = collate ( importB ) ;
256
+
249
257
let result ;
250
258
251
259
if ( importA < importB ) {
@@ -281,13 +289,9 @@ function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
281
289
const groupRanks = Object . keys ( groupedByRanks ) ;
282
290
283
291
const sorterFn = getSorter ( alphabetizeOptions . order === 'asc' ) ;
284
- const comparator =
285
- alphabetizeOptions . caseInsensitive === 'invert' ? ( a , b ) => sorterFn ( swapCase ( String ( a ) ) , swapCase ( String ( b ) ) )
286
- : alphabetizeOptions . caseInsensitive ? ( a , b ) => sorterFn ( String ( a ) . toLowerCase ( ) , String ( b ) . toLowerCase ( ) )
287
- : ( a , b ) => sorterFn ( a , b ) ;
288
292
// sort imports locally within their group
289
293
groupRanks . forEach ( function ( groupRank ) {
290
- groupedByRanks [ groupRank ] . sort ( comparator ) ;
294
+ groupedByRanks [ groupRank ] . sort ( sorterFn ) ;
291
295
} ) ;
292
296
293
297
// assign globally unique rank to each import
0 commit comments