Skip to content

Commit 0872bdd

Browse files
authored
feat: generate exception if group does not exist
1 parent d9c72d2 commit 0872bdd

21 files changed

+480
-5
lines changed

rules/sort-astro-attributes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'node:path'
55

66
import type { SortingNode } from '../typings'
77

8+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
89
import { createEslintRule } from '../utils/create-eslint-rule'
910
import { getGroupNumber } from '../utils/get-group-number'
1011
import { getSourceCode } from '../utils/get-source-code'
@@ -138,6 +139,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
138139
groups: [],
139140
} as const)
140141

142+
validateGroupsConfiguration(
143+
options.groups,
144+
['astro-shorthand', 'multiline', 'shorthand', 'unknown'],
145+
Object.keys(options.customGroups),
146+
)
147+
141148
let sourceCode = getSourceCode(context)
142149

143150
let parts: SortingNode[][] = attributes.reduce(

rules/sort-imports.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { minimatch } from 'minimatch'
66

77
import type { SortingNode } from '../typings'
88

9+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
910
import { getCommentBefore } from '../utils/get-comment-before'
1011
import { createEslintRule } from '../utils/create-eslint-rule'
1112
import { getLinesBetween } from '../utils/get-lines-between'
@@ -256,6 +257,34 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
256257
options.groups = [...options.groups, 'unknown']
257258
}
258259

260+
validateGroupsConfiguration(
261+
options.groups,
262+
[
263+
'side-effect-style',
264+
'external-type',
265+
'internal-type',
266+
'builtin-type',
267+
'sibling-type',
268+
'parent-type',
269+
'side-effect',
270+
'index-type',
271+
'internal',
272+
'external',
273+
'sibling',
274+
'unknown',
275+
'builtin',
276+
'parent',
277+
'object',
278+
'index',
279+
'style',
280+
'type',
281+
],
282+
[
283+
...Object.keys(options.customGroups.type ?? {}),
284+
...Object.keys(options.customGroups.value ?? {}),
285+
],
286+
)
287+
259288
let nodes: SortingNode[] = []
260289

261290
let isSideEffectImport = (node: TSESTree.Node) =>

rules/sort-interfaces.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { minimatch } from 'minimatch'
22

33
import type { SortingNode } from '../typings'
44

5+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
56
import { createEslintRule } from '../utils/create-eslint-rule'
67
import { isMemberOptional } from '../utils/is-member-optional'
78
import { getLinesBetween } from '../utils/get-lines-between'
@@ -151,6 +152,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
151152
groups: [],
152153
} as const)
153154

155+
validateGroupsConfiguration(
156+
options.groups,
157+
['multiline', 'unknown'],
158+
Object.keys(options.customGroups),
159+
)
160+
154161
let sourceCode = getSourceCode(context)
155162

156163
if (

rules/sort-intersection-types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SortingNode } from '../typings'
22

3+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
34
import { createEslintRule } from '../utils/create-eslint-rule'
45
import { getGroupNumber } from '../utils/get-group-number'
56
import { getSourceCode } from '../utils/get-source-code'
@@ -113,6 +114,26 @@ export default createEslintRule<Options, MESSAGE_ID>({
113114
groups: [],
114115
} as const)
115116

117+
validateGroupsConfiguration(
118+
options.groups,
119+
[
120+
'intersection',
121+
'conditional',
122+
'function',
123+
'operator',
124+
'keyword',
125+
'literal',
126+
'nullish',
127+
'unknown',
128+
'import',
129+
'object',
130+
'named',
131+
'tuple',
132+
'union',
133+
],
134+
[],
135+
)
136+
116137
let sourceCode = getSourceCode(context)
117138

118139
let nodes: SortingNode[] = node.types.map(type => {

rules/sort-jsx-props.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { minimatch } from 'minimatch'
44

55
import type { SortingNode } from '../typings'
66

7+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
78
import { createEslintRule } from '../utils/create-eslint-rule'
89
import { getGroupNumber } from '../utils/get-group-number'
910
import { getSourceCode } from '../utils/get-source-code'
@@ -139,6 +140,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
139140
groups: [],
140141
} as const)
141142

143+
validateGroupsConfiguration(
144+
options.groups,
145+
['multiline', 'shorthand', 'unknown'],
146+
Object.keys(options.customGroups),
147+
)
148+
142149
let sourceCode = getSourceCode(context)
143150

144151
let shouldIgnore = false

rules/sort-object-types.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { TSESTree } from '@typescript-eslint/types'
22

33
import type { SortingNode } from '../typings'
44

5+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
56
import { createEslintRule } from '../utils/create-eslint-rule'
67
import { getLinesBetween } from '../utils/get-lines-between'
78
import { getGroupNumber } from '../utils/get-group-number'
@@ -24,12 +25,12 @@ type Group<T extends string[]> = 'multiline' | 'unknown' | T[number]
2425
type Options<T extends string[]> = [
2526
Partial<{
2627
groupKind: 'required-first' | 'optional-first' | 'mixed'
28+
customGroups: { [key in T[number]]: string[] | string }
2729
type: 'alphabetical' | 'line-length' | 'natural'
2830
groups: (Group<T>[] | Group<T>)[]
2931
partitionByNewLine: boolean
3032
order: 'desc' | 'asc'
3133
ignoreCase: boolean
32-
customGroups: {}
3334
}>,
3435
]
3536

@@ -140,6 +141,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
140141
groups: [],
141142
} as const)
142143

144+
validateGroupsConfiguration(
145+
options.groups,
146+
['multiline', 'unknown'],
147+
Object.keys(options.customGroups),
148+
)
149+
143150
let sourceCode = getSourceCode(context)
144151

145152
let formattedMembers: SortingNode<TSESTree.TypeElement>[][] =

rules/sort-objects.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { minimatch } from 'minimatch'
55

66
import type { SortingNode } from '../typings'
77

8+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
89
import { isPartitionComment } from '../utils/is-partition-comment'
910
import { getCommentBefore } from '../utils/get-comment-before'
1011
import { createEslintRule } from '../utils/create-eslint-rule'
@@ -30,6 +31,8 @@ export enum Position {
3031
'ignore' = 'ignore',
3132
}
3233

34+
type Group = 'unknown' | string
35+
3336
type SortingNodeWithPosition = {
3437
position: Position
3538
} & SortingNode
@@ -39,7 +42,7 @@ type Options = [
3942
customGroups: { [key: string]: string[] | string }
4043
type: 'alphabetical' | 'line-length' | 'natural'
4144
partitionByComment: string[] | boolean | string
42-
groups: (string[] | string)[]
45+
groups: (Group[] | Group)[]
4346
partitionByNewLine: boolean
4447
styledComponents: boolean
4548
destructureOnly: boolean
@@ -191,6 +194,12 @@ export default createEslintRule<Options, MESSAGE_ID>({
191194
groups: [],
192195
} as const)
193196

197+
validateGroupsConfiguration(
198+
options.groups,
199+
['unknown'],
200+
Object.keys(options.customGroups),
201+
)
202+
194203
let shouldIgnore = false
195204

196205
if (options.destructureOnly) {

rules/sort-svelte-attributes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'node:path'
55

66
import type { SortingNode } from '../typings'
77

8+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
89
import { createEslintRule } from '../utils/create-eslint-rule'
910
import { getGroupNumber } from '../utils/get-group-number'
1011
import { getSourceCode } from '../utils/get-source-code'
@@ -135,6 +136,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
135136
groups: [],
136137
} as const)
137138

139+
validateGroupsConfiguration(
140+
options.groups,
141+
['svelte-shorthand', 'multiline', 'shorthand', 'unknown'],
142+
Object.keys(options.customGroups),
143+
)
144+
138145
let sourceCode = getSourceCode(context)
139146

140147
let parts: SortingNode[][] = node.attributes.reduce(

rules/sort-union-types.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import type { SortingNode } from '../typings'
22

3+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
34
import { createEslintRule } from '../utils/create-eslint-rule'
45
import { getGroupNumber } from '../utils/get-group-number'
56
import { getSourceCode } from '../utils/get-source-code'
@@ -113,6 +114,26 @@ export default createEslintRule<Options, MESSAGE_ID>({
113114
groups: [],
114115
} as const)
115116

117+
validateGroupsConfiguration(
118+
options.groups,
119+
[
120+
'intersection',
121+
'conditional',
122+
'function',
123+
'operator',
124+
'keyword',
125+
'literal',
126+
'nullish',
127+
'unknown',
128+
'import',
129+
'object',
130+
'named',
131+
'tuple',
132+
'union',
133+
],
134+
[],
135+
)
136+
116137
let sourceCode = getSourceCode(context)
117138

118139
let nodes: SortingNode[] = node.types.map(type => {

rules/sort-vue-attributes.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import path from 'node:path'
55

66
import type { SortingNode } from '../typings'
77

8+
import { validateGroupsConfiguration } from '../utils/validate-groups-configuration'
89
import { createEslintRule } from '../utils/create-eslint-rule'
910
import { getGroupNumber } from '../utils/get-group-number'
1011
import { getSourceCode } from '../utils/get-source-code'
@@ -147,6 +148,12 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
147148
groups: [],
148149
} as const)
149150

151+
validateGroupsConfiguration(
152+
options.groups,
153+
['multiline', 'shorthand', 'unknown'],
154+
Object.keys(options.customGroups),
155+
)
156+
150157
let parts: SortingNode[][] = node.attributes.reduce(
151158
(accumulator: SortingNode[][], attribute) => {
152159
if (

0 commit comments

Comments
 (0)