diff --git a/rules/sort-imports.ts b/rules/sort-imports.ts index edb41a5..a3aa0c2 100644 --- a/rules/sort-imports.ts +++ b/rules/sort-imports.ts @@ -201,8 +201,9 @@ export default createEslintRule, MESSAGE_ID>({ tsPaths.some(pattern => minimatch(nodeElement.source.value, pattern)) let isCoreModule = (value: string) => - builtinModules.includes(value) || - builtinModules.includes(`node:${value}`) + builtinModules.includes( + value.startsWith('node:') ? value.split('node:')[1] : value, + ) if (node.importKind === 'type') { if (node.type === 'ImportDeclaration') { diff --git a/test/sort-imports.test.ts b/test/sort-imports.test.ts index 5b2fc82..ef58770 100644 --- a/test/sort-imports.test.ts +++ b/test/sort-imports.test.ts @@ -3232,5 +3232,53 @@ describe(RULE_NAME, () => { invalid: [], }, ) + + ruleTester.run( + `${RULE_NAME}: defines prefix-only builtin modules as core node modules`, + rule, + { + valid: [ + { + code: dedent` + import { writeFile } from 'node:fs/promises' + + import { useEffect } from 'react' + `, + options: [ + { + groups: ['builtin', 'external'], + }, + ], + }, + ], + invalid: [ + { + code: dedent` + import { writeFile } from 'node:fs/promises' + import { useEffect } from 'react' + `, + output: dedent` + import { writeFile } from 'node:fs/promises' + + import { useEffect } from 'react' + `, + options: [ + { + groups: ['builtin', 'external'], + }, + ], + errors: [ + { + messageId: 'missedSpacingBetweenImports', + data: { + left: 'node:fs/promises', + right: 'react', + }, + }, + ], + }, + ], + }, + ) }) })