diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index e60af0f9..90cec3e9 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -222,24 +222,24 @@ export default createEslintRule, MESSAGE_ID>({ if (node.type === 'ImportDeclaration') { setCustomGroups(options['custom-groups'].type, node.source.value) - if (isCoreModule(node.source.value)) { - defineGroup('builtin-type') - } - - if (isInternal(node)) { - defineGroup('internal-type') - } - if (isIndex(node.source.value)) { defineGroup('index-type') } + if (isSibling(node.source.value)) { + defineGroup('sibling-type') + } + if (isParent(node.source.value)) { defineGroup('parent-type') } - if (isSibling(node.source.value)) { - defineGroup('sibling-type') + if (isInternal(node)) { + defineGroup('internal-type') + } + + if (isCoreModule(node.source.value)) { + defineGroup('builtin-type') } } @@ -250,32 +250,32 @@ export default createEslintRule, MESSAGE_ID>({ if (node.type === 'ImportDeclaration') { setCustomGroups(options['custom-groups'].value, node.source.value) - if (isCoreModule(node.source.value)) { - defineGroup('builtin') - } - - if (isInternal(node)) { - defineGroup('internal') + if (isSideEffectImport(node)) { + defineGroup('side-effect') } if (isStyle(node.source.value)) { defineGroup('style') } - if (isSideEffectImport(node)) { - defineGroup('side-effect') - } - if (isIndex(node.source.value)) { defineGroup('index') } + if (isSibling(node.source.value)) { + defineGroup('sibling') + } + if (isParent(node.source.value)) { defineGroup('parent') } - if (isSibling(node.source.value)) { - defineGroup('sibling') + if (isInternal(node)) { + defineGroup('internal') + } + + if (isCoreModule(node.source.value)) { + defineGroup('builtin') } defineGroup('external') diff --git a/test/sort-imports.test.ts b/test/sort-imports.test.ts index 8b3994c1..96983576 100644 --- a/test/sort-imports.test.ts +++ b/test/sort-imports.test.ts @@ -3608,5 +3608,53 @@ describe(RULE_NAME, () => { ], }, ) + + ruleTester.run( + `${RULE_NAME}: define side-effect import with internal pattern as side-effect import`, + rule, + { + valid: [ + { + code: dedent` + import { useClient } from '~/hooks/useClient' + + import '~/css/globals.css' + `, + options: [ + { + groups: ['internal', 'side-effect'], + }, + ], + }, + ], + invalid: [ + { + code: dedent` + import { useClient } from '~/hooks/useClient' + import '~/css/globals.css' + `, + output: dedent` + import { useClient } from '~/hooks/useClient' + + import '~/css/globals.css' + `, + options: [ + { + groups: ['internal', 'side-effect'], + }, + ], + errors: [ + { + messageId: 'missedSpacingBetweenImports', + data: { + left: '~/hooks/useClient', + right: '~/css/globals.css', + }, + }, + ], + }, + ], + }, + ) }) })