Skip to content

Commit 73a67b2

Browse files
committed
refactor: create OptionsByGroupIndexComputer type
1 parent 6552895 commit 73a67b2

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

test/utils/sort-nodes-by-groups.test.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { describe, expect, it } from 'vitest'
22

3+
import type { OptionsByGroupIndexComputer } from '../../utils/sort-nodes-by-groups'
34
import type { CommonOptions } from '../../types/common-options'
45
import type { SortingNode } from '../../types/sorting-node'
56

@@ -15,9 +16,10 @@ describe('sort-nodes-by-groups', () => {
1516
order: 'asc',
1617
alphabet: '',
1718
} as const
18-
let optionsByGroupIndexComputer: () => {
19-
options: CommonOptions
20-
} = () => ({ options })
19+
let optionsByGroupIndexComputer: OptionsByGroupIndexComputer<
20+
CommonOptions,
21+
SortingNode
22+
> = () => ({ options })
2123

2224
it('sorts nodes by groups', () => {
2325
let nodeA = createTestNode({ group: 'group2', name: 'a' })

utils/sort-nodes-by-groups.ts

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,15 @@ import type { SortingNode } from '../types/sorting-node'
55
import { getGroupIndex } from './get-group-index'
66
import { sortNodes } from './sort-nodes'
77

8+
export type OptionsByGroupIndexComputer<
9+
Options extends CommonOptions,
10+
T extends SortingNode,
11+
> = (groupIndex: number) => {
12+
fallbackSortNodeValueGetter?: NodeValueGetterFunction<T> | null
13+
nodeValueGetter?: NodeValueGetterFunction<T> | null
14+
options: Options
15+
}
16+
817
/**
918
* Parameters for sorting nodes by groups.
1019
*
@@ -15,16 +24,12 @@ interface SortNodesByGroupsParameters<
1524
Options extends CommonOptions,
1625
T extends SortingNode,
1726
> {
18-
optionsByGroupIndexComputer(groupIndex: number): {
19-
fallbackSortNodeValueGetter?: NodeValueGetterFunction<T> | null
20-
nodeValueGetter?: NodeValueGetterFunction<T> | null
21-
options: Options
22-
}
2327
isNodeIgnoredForGroup?(props: {
2428
groupOptions: Options
2529
groupIndex: number
2630
node: T
2731
}): boolean
32+
optionsByGroupIndexComputer: OptionsByGroupIndexComputer<Options, T>
2833
ignoreEslintDisabledNodes: boolean
2934
isNodeIgnored?(node: T): boolean
3035
groups: GroupsOptions<string>

0 commit comments

Comments
 (0)