Skip to content

Commit c39c7e8

Browse files
committed
feat: ordering by configuration
1 parent cd79f13 commit c39c7e8

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/cliOptions.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,13 @@ export const optionDefinitions = [
2525
multiple: true,
2626
description: 'The prefix of custom user libraries',
2727
},
28+
{
29+
name: 'groupOrder',
30+
alias: 'g',
31+
type: String,
32+
multiple: true,
33+
description: 'The group order should be organized',
34+
},
2835
{
2936
name: 'staged',
3037
type: Boolean,

src/conductor/format-import-statements.ts

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,11 @@ import { ImportCategories } from '../types';
33

44
type CategoryEntry = [string, Map<string, string>];
55

6-
const categoriesOrder = ['thirdParty', 'userLibrary', 'differentModule', 'sameModule']; // <<<<
7-
86
export function formatImportStatements(importCategories: ImportCategories, lineEnding: string) {
97
const { separator } = getConfig();
108
const [first, ...otherCategories] = Object.entries(importCategories)
119
.filter(hasImports)
12-
.sort(byCategoriesOrder)
10+
.sort(byCategoriesOrder(getConfig().groupOrder))
1311
.map((imports) => toImportBlock(imports, lineEnding));
1412

1513
let result = first || '';
@@ -21,8 +19,8 @@ export function formatImportStatements(importCategories: ImportCategories, lineE
2119
return result;
2220
}
2321

24-
function byCategoriesOrder([a]: CategoryEntry, [b]: CategoryEntry): number {
25-
return categoriesOrder.indexOf(a) - categoriesOrder.indexOf(b);
22+
function byCategoriesOrder(categoriesOrder: string[]) {
23+
return ([a]: CategoryEntry, [b]: CategoryEntry): number => categoriesOrder.indexOf(a) - categoriesOrder.indexOf(b);
2624
}
2725

2826
function hasImports([, imports]: CategoryEntry) {

0 commit comments

Comments
 (0)