From a0208ace711a480cfa3de0091c5b701bba71cd4f Mon Sep 17 00:00:00 2001 From: "Azat S." Date: Sat, 20 Jul 2024 02:08:39 +0300 Subject: [PATCH] fix: fix export and import kind default value --- rules/sort-named-exports.ts | 20 ++++++++++++++------ rules/sort-named-imports.ts | 20 +++++++++++++------- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/rules/sort-named-exports.ts b/rules/sort-named-exports.ts index 5d64b873d..4d36a58db 100644 --- a/rules/sort-named-exports.ts +++ b/rules/sort-named-exports.ts @@ -82,12 +82,20 @@ export default createEslintRule({ let sourceCode = getSourceCode(context) - let nodes: SortingNode[] = node.specifiers.map(specifier => ({ - size: rangeToDiff(specifier.range), - name: specifier.local.name, - node: specifier, - group: specifier.exportKind, - })) + let nodes: SortingNode[] = node.specifiers.map(specifier => { + let group: undefined | 'value' | 'type' + if (specifier.exportKind === 'type') { + group = 'type' + } else { + group = 'value' + } + return { + size: rangeToDiff(specifier.range), + name: specifier.local.name, + node: specifier, + group, + } + }) let shouldGroupByKind = options.groupKind !== 'mixed' let groupKindOrder = diff --git a/rules/sort-named-imports.ts b/rules/sort-named-imports.ts index 92d5e4c9f..1ac2ce767 100644 --- a/rules/sort-named-imports.ts +++ b/rules/sort-named-imports.ts @@ -93,21 +93,27 @@ export default createEslintRule({ let sourceCode = getSourceCode(context) let nodes: SortingNode[] = specifiers.map(specifier => { - let group = 'unknown' + let group: undefined | 'value' | 'type' let { name } = specifier.local - if (specifier.type === 'ImportSpecifier') { - if (options.ignoreAlias) { - ;({ name } = specifier.imported) - } - group = specifier.importKind + if (specifier.type === 'ImportSpecifier' && options.ignoreAlias) { + ;({ name } = specifier.imported) + } + + if ( + specifier.type === 'ImportSpecifier' && + specifier.importKind === 'type' + ) { + group = 'type' + } else { + group = 'value' } return { size: rangeToDiff(specifier.range), node: specifier, - name, group, + name, } })