diff --git a/package.json b/package.json index e870082e3..c214e5955 100644 --- a/package.json +++ b/package.json @@ -114,6 +114,7 @@ "is-glob": "^4.0.3", "minimatch": "^3.1.2", "object.fromentries": "^2.0.6", + "object.groupby": "^1.0.0", "object.values": "^1.1.6", "resolve": "^1.22.3", "semver": "^6.3.1", diff --git a/src/rules/order.js b/src/rules/order.js index 27c3f4b0f..6f70db263 100644 --- a/src/rules/order.js +++ b/src/rules/order.js @@ -2,6 +2,7 @@ import minimatch from 'minimatch'; import includes from 'array-includes'; +import groupBy from 'object.groupby'; import importType from '../core/importType'; import isStaticRequire from '../core/staticRequire'; @@ -325,13 +326,7 @@ function getSorter(alphabetizeOptions) { } function mutateRanksToAlphabetize(imported, alphabetizeOptions) { - const groupedByRanks = imported.reduce(function (acc, importedItem) { - if (!Array.isArray(acc[importedItem.rank])) { - acc[importedItem.rank] = []; - } - acc[importedItem.rank].push(importedItem); - return acc; - }, {}); + const groupedByRanks = groupBy(imported, (item) => item.rank); const sorterFn = getSorter(alphabetizeOptions);