Skip to content

Commit 600fcc1

Browse files
committedJul 28, 2023
[Refactor] order: use object.groupby
1 parent be928ae commit 600fcc1

File tree

2 files changed

+3
-7
lines changed

2 files changed

+3
-7
lines changed
 

Diff for: ‎package.json

+1
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@
114114
"is-glob": "^4.0.3",
115115
"minimatch": "^3.1.2",
116116
"object.fromentries": "^2.0.6",
117+
"object.groupby": "^1.0.0",
117118
"object.values": "^1.1.6",
118119
"resolve": "^1.22.3",
119120
"semver": "^6.3.1",

Diff for: ‎src/rules/order.js

+2-7
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import minimatch from 'minimatch';
44
import includes from 'array-includes';
5+
import groupBy from 'object.groupby';
56

67
import importType from '../core/importType';
78
import isStaticRequire from '../core/staticRequire';
@@ -325,13 +326,7 @@ function getSorter(alphabetizeOptions) {
325326
}
326327

327328
function mutateRanksToAlphabetize(imported, alphabetizeOptions) {
328-
const groupedByRanks = imported.reduce(function (acc, importedItem) {
329-
if (!Array.isArray(acc[importedItem.rank])) {
330-
acc[importedItem.rank] = [];
331-
}
332-
acc[importedItem.rank].push(importedItem);
333-
return acc;
334-
}, {});
329+
const groupedByRanks = groupBy(imported, (item) => item.rank);
335330

336331
const sorterFn = getSorter(alphabetizeOptions);
337332

0 commit comments

Comments
 (0)
Please sign in to comment.