From 23be85cd371d4e493c756e03dee480fb748a9e08 Mon Sep 17 00:00:00 2001 From: dbrewer5 Date: Thu, 26 Dec 2019 18:08:59 -0800 Subject: [PATCH] imp: merged mutateRanksToAlphabetizeV2 to original --- src/rules/order.js | 37 ++----------------------------------- 1 file changed, 2 insertions(+), 35 deletions(-) diff --git a/src/rules/order.js b/src/rules/order.js index 9004dd7aa5..f6e29a4306 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -267,7 +267,7 @@ function importsSorterDesc(importA, importB) { return 0 } -function mutateRanksToAlphabetizeV2(imported, alphabetizeOptions) { +function mutateRanksToAlphabetize(imported, alphabetizeOptions) { const groupedByRanks = imported.reduce(function(acc, importedItem) { if (!Array.isArray(acc[importedItem.rank])) { acc[importedItem.rank] = [] @@ -304,39 +304,6 @@ function mutateRanksToAlphabetizeV2(imported, alphabetizeOptions) { }) } -function mutateRanksToAlphabetize(imported, order) { - const groupedByRanks = imported.reduce(function(acc, importedItem) { - if (!Array.isArray(acc[importedItem.rank])) { - acc[importedItem.rank] = [] - } - acc[importedItem.rank].push(importedItem.name) - return acc - }, {}) - - const groupRanks = Object.keys(groupedByRanks) - - const sorterFn = order === 'asc' ? importsSorterAsc : importsSorterDesc - // sort imports locally within their group - groupRanks.forEach(function(groupRank) { - groupedByRanks[groupRank].sort(sorterFn) - }) - - // assign globally unique rank to each import - let newRank = 0 - const alphabetizedRanks = groupRanks.sort().reduce(function(acc, groupRank) { - groupedByRanks[groupRank].forEach(function(importedItemName) { - acc[importedItemName] = newRank - newRank += 1 - }) - return acc - }, {}) - - // mutate the original group-rank with alphabetized-rank - imported.forEach(function(importedItem) { - importedItem.rank = alphabetizedRanks[importedItem.name] - }) -} - // DETECTING function computePathRank(ranks, pathGroups, path, maxPosition) { @@ -646,7 +613,7 @@ module.exports = { } if (alphabetize.order !== 'ignore') { - mutateRanksToAlphabetizeV2(imported, alphabetize) + mutateRanksToAlphabetize(imported, alphabetize) } makeOutOfOrderReport(context, imported)