Skip to content

Commit b6f4e91

Browse files
authoredSep 13, 2023
fix: side-effect import with an internal pattern are defined as internal module in sort-imports rule
1 parent c4a922c commit b6f4e91

File tree

2 files changed

+70
-22
lines changed

2 files changed

+70
-22
lines changed
 

‎rules/sort-imports.ts

+22-22
Original file line numberDiff line numberDiff line change
@@ -222,24 +222,24 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
222222
if (node.type === 'ImportDeclaration') {
223223
setCustomGroups(options['custom-groups'].type, node.source.value)
224224

225-
if (isCoreModule(node.source.value)) {
226-
defineGroup('builtin-type')
227-
}
228-
229-
if (isInternal(node)) {
230-
defineGroup('internal-type')
231-
}
232-
233225
if (isIndex(node.source.value)) {
234226
defineGroup('index-type')
235227
}
236228

229+
if (isSibling(node.source.value)) {
230+
defineGroup('sibling-type')
231+
}
232+
237233
if (isParent(node.source.value)) {
238234
defineGroup('parent-type')
239235
}
240236

241-
if (isSibling(node.source.value)) {
242-
defineGroup('sibling-type')
237+
if (isInternal(node)) {
238+
defineGroup('internal-type')
239+
}
240+
241+
if (isCoreModule(node.source.value)) {
242+
defineGroup('builtin-type')
243243
}
244244
}
245245

@@ -250,32 +250,32 @@ export default createEslintRule<Options<string[]>, MESSAGE_ID>({
250250
if (node.type === 'ImportDeclaration') {
251251
setCustomGroups(options['custom-groups'].value, node.source.value)
252252

253-
if (isCoreModule(node.source.value)) {
254-
defineGroup('builtin')
255-
}
256-
257-
if (isInternal(node)) {
258-
defineGroup('internal')
253+
if (isSideEffectImport(node)) {
254+
defineGroup('side-effect')
259255
}
260256

261257
if (isStyle(node.source.value)) {
262258
defineGroup('style')
263259
}
264260

265-
if (isSideEffectImport(node)) {
266-
defineGroup('side-effect')
267-
}
268-
269261
if (isIndex(node.source.value)) {
270262
defineGroup('index')
271263
}
272264

265+
if (isSibling(node.source.value)) {
266+
defineGroup('sibling')
267+
}
268+
273269
if (isParent(node.source.value)) {
274270
defineGroup('parent')
275271
}
276272

277-
if (isSibling(node.source.value)) {
278-
defineGroup('sibling')
273+
if (isInternal(node)) {
274+
defineGroup('internal')
275+
}
276+
277+
if (isCoreModule(node.source.value)) {
278+
defineGroup('builtin')
279279
}
280280

281281
defineGroup('external')

‎test/sort-imports.test.ts

+48
Original file line numberDiff line numberDiff line change
@@ -3608,5 +3608,53 @@ describe(RULE_NAME, () => {
36083608
],
36093609
},
36103610
)
3611+
3612+
ruleTester.run(
3613+
`${RULE_NAME}: define side-effect import with internal pattern as side-effect import`,
3614+
rule,
3615+
{
3616+
valid: [
3617+
{
3618+
code: dedent`
3619+
import { useClient } from '~/hooks/useClient'
3620+
3621+
import '~/css/globals.css'
3622+
`,
3623+
options: [
3624+
{
3625+
groups: ['internal', 'side-effect'],
3626+
},
3627+
],
3628+
},
3629+
],
3630+
invalid: [
3631+
{
3632+
code: dedent`
3633+
import { useClient } from '~/hooks/useClient'
3634+
import '~/css/globals.css'
3635+
`,
3636+
output: dedent`
3637+
import { useClient } from '~/hooks/useClient'
3638+
3639+
import '~/css/globals.css'
3640+
`,
3641+
options: [
3642+
{
3643+
groups: ['internal', 'side-effect'],
3644+
},
3645+
],
3646+
errors: [
3647+
{
3648+
messageId: 'missedSpacingBetweenImports',
3649+
data: {
3650+
left: '~/hooks/useClient',
3651+
right: '~/css/globals.css',
3652+
},
3653+
},
3654+
],
3655+
},
3656+
],
3657+
},
3658+
)
36113659
})
36123660
})

0 commit comments

Comments
 (0)
Please sign in to comment.