Skip to content

Commit

Permalink
[Refactor] order: use object.groupby
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Jul 28, 2023
1 parent be928ae commit 600fcc1
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 7 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 2 additions & 7 deletions src/rules/order.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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);

Expand Down

0 comments on commit 600fcc1

Please sign in to comment.