Skip to content

Commit 20f1795

Browse files
committed
feat: add import and value selectors/modifiers
1 parent 8e025e6 commit 20f1795

2 files changed

Lines changed: 21 additions & 2 deletions

File tree

rules/sort-imports.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,9 @@ export default createEslintRule<Options, MESSAGE_ID>({
172172
let modifiers: Modifier[] = []
173173
let group: Group | null = null
174174

175+
let isTypeImport = false
175176
if (node.type !== 'VariableDeclaration' && node.importKind === 'type') {
177+
isTypeImport = true
176178
if (node.type === 'ImportDeclaration') {
177179
if (!Array.isArray(options.customGroups)) {
178180
group = computeGroupExceptUnknown({
@@ -199,6 +201,8 @@ export default createEslintRule<Options, MESSAGE_ID>({
199201
name,
200202
})
201203
}
204+
} else {
205+
modifiers.push('value')
202206
}
203207

204208
let isSideEffect = isSideEffectImport({ sourceCode, node })
@@ -229,6 +233,11 @@ export default createEslintRule<Options, MESSAGE_ID>({
229233
selectors.push(selector)
230234
}
231235

236+
if (!isTypeImport) {
237+
selectors.push('value')
238+
}
239+
selectors.push('import')
240+
232241
group ??=
233242
computeGroupExceptUnknown({
234243
customGroups: Array.isArray(options.customGroups)

rules/sort-imports/types.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,10 @@ export type Selector =
6161
| SiblingSelector
6262
| ParentSelector
6363
| ObjectSelector
64+
| ImportSelector
6465
| IndexSelector
6566
| StyleSelector
67+
| ValueSelector
6668
| TypeSelector
6769

6870
export type SingleCustomGroup = {
@@ -78,7 +80,7 @@ export interface SortImportsSortingNode extends SortingNode {
7880

7981
export type Group = ValueGroup | TypeGroup | 'unknown' | string
8082

81-
export type Modifier = TypeModifier
83+
export type Modifier = ValueModifier | TypeModifier
8284

8385
type TypeGroup = JoinWithDash<[TypeModifier, Selector]>
8486

@@ -130,10 +132,16 @@ type ParentSelector = 'parent'
130132

131133
type ObjectSelector = 'object'
132134

135+
type ImportSelector = 'import'
136+
137+
type ValueModifier = 'value'
138+
133139
type IndexSelector = 'index'
134140

135141
type StyleSelector = 'style'
136142

143+
type ValueSelector = 'value'
144+
137145
type TypeModifier = 'type'
138146

139147
type TypeSelector = 'type'
@@ -149,6 +157,8 @@ export let allSelectors: Selector[] = [
149157
'object',
150158
'index',
151159
'style',
160+
'value',
161+
'import',
152162
'type',
153163
]
154164

@@ -161,7 +171,7 @@ export let allDeprecatedSelectors: Selector[] = [
161171
'index-type',
162172
]
163173

164-
export let allModifiers: Modifier[] = ['value', 'type']
174+
export let allModifiers: Modifier[] = ['type', 'value']
165175

166176
/**
167177
* Ideally, we should generate as many schemas as there are selectors, and ensure

0 commit comments

Comments
 (0)