Skip to content

Commit

Permalink
fix: side-effect import with an internal pattern are defined as inter…
Browse files Browse the repository at this point in the history
…nal module in sort-imports rule
  • Loading branch information
Wondermarin authored Sep 13, 2023
1 parent c4a922c commit b6f4e91
Show file tree
Hide file tree
Showing 2 changed files with 70 additions and 22 deletions.
44 changes: 22 additions & 22 deletions rules/sort-imports.ts
Original file line number Diff line number Diff line change
Expand Up @@ -222,24 +222,24 @@ export default createEslintRule<Options<string[]>, 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')
}
}

Expand All @@ -250,32 +250,32 @@ export default createEslintRule<Options<string[]>, 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')
Expand Down
48 changes: 48 additions & 0 deletions test/sort-imports.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
},
},
],
},
],
},
)
})
})

0 comments on commit b6f4e91

Please sign in to comment.