diff --git a/rules/sort-exports.ts b/rules/sort-exports.ts index 8007d1b55..c5983c9b9 100644 --- a/rules/sort-exports.ts +++ b/rules/sort-exports.ts @@ -82,15 +82,11 @@ export default createEslintRule({ | TSESTree.ExportNamedDeclarationWithSource | TSESTree.ExportAllDeclaration, ) => { - if (node.type === 'ExportAllDeclaration' && node.exported === null) { - parts.push([]) - } else { - parts.at(-1)!.push({ - size: rangeToDiff(node.range), - name: node.source.value, - node, - }) - } + parts.at(-1)!.push({ + size: rangeToDiff(node.range), + name: node.source.value, + node, + }) } return { diff --git a/test/sort-exports.test.ts b/test/sort-exports.test.ts index 4ff3d15fb..ac17f3c12 100644 --- a/test/sort-exports.test.ts +++ b/test/sort-exports.test.ts @@ -73,52 +73,55 @@ describe(RULE_NAME, () => { ], }) - ruleTester.run( - `${RULE_NAME}(${type}): sorts all-exports only if export kind is value`, - rule, - { - valid: [ - { - code: dedent` - export { SuzuHoujou } from './houjou' - export * as Kuromura from './kuromura' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - }, - ], - invalid: [ - { - code: dedent` - export * as Kuromura from './kuromura' - export { SuzuHoujou } from './houjou' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - output: dedent` - export { SuzuHoujou } from './houjou' - export * as Kuromura from './kuromura' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - errors: [ - { - messageId: 'unexpectedExportsOrder', - data: { - left: './kuromura', - right: './houjou', - }, + ruleTester.run(`${RULE_NAME}(${type}): sorts all-exports`, rule, { + valid: [ + { + code: dedent` + export { SuzuHoujou } from './houjou' + export * as Kuromura from './kuromura' + export { TetsuMizuhara } from './mizuhara' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + }, + ], + invalid: [ + { + code: dedent` + export * as Kuromura from './kuromura' + export { SuzuHoujou } from './houjou' + export { TetsuMizuhara } from './mizuhara' + export * from 'hiroshima' + export { Shuusaku } from './shuusaku' + `, + output: dedent` + export { SuzuHoujou } from './houjou' + export * as Kuromura from './kuromura' + export { TetsuMizuhara } from './mizuhara' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + errors: [ + { + messageId: 'unexpectedExportsOrder', + data: { + left: './kuromura', + right: './houjou', }, - ], - }, - ], - }, - ) + }, + { + messageId: 'unexpectedExportsOrder', + data: { + left: 'hiroshima', + right: './shuusaku', + }, + }, + ], + }, + ], + }) ruleTester.run(`${RULE_NAME}(${type}): works with export aliases`, rule, { valid: [ @@ -214,52 +217,55 @@ describe(RULE_NAME, () => { ], }) - ruleTester.run( - `${RULE_NAME}(${type}): sorts all-exports only if export kind is value`, - rule, - { - valid: [ - { - code: dedent` - export { SuzuHoujou } from './houjou' - export * as Kuromura from './kuromura' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - }, - ], - invalid: [ - { - code: dedent` - export * as Kuromura from './kuromura' - export { SuzuHoujou } from './houjou' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - output: dedent` - export { SuzuHoujou } from './houjou' - export * as Kuromura from './kuromura' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - errors: [ - { - messageId: 'unexpectedExportsOrder', - data: { - left: './kuromura', - right: './houjou', - }, + ruleTester.run(`${RULE_NAME}(${type}): sorts all-exports`, rule, { + valid: [ + { + code: dedent` + export { SuzuHoujou } from './houjou' + export * as Kuromura from './kuromura' + export { TetsuMizuhara } from './mizuhara' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + }, + ], + invalid: [ + { + code: dedent` + export * as Kuromura from './kuromura' + export { SuzuHoujou } from './houjou' + export { TetsuMizuhara } from './mizuhara' + export * from 'hiroshima' + export { Shuusaku } from './shuusaku' + `, + output: dedent` + export { SuzuHoujou } from './houjou' + export * as Kuromura from './kuromura' + export { TetsuMizuhara } from './mizuhara' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + errors: [ + { + messageId: 'unexpectedExportsOrder', + data: { + left: './kuromura', + right: './houjou', }, - ], - }, - ], - }, - ) + }, + { + messageId: 'unexpectedExportsOrder', + data: { + left: 'hiroshima', + right: './shuusaku', + }, + }, + ], + }, + ], + }) ruleTester.run(`${RULE_NAME}(${type}): works with export aliases`, rule, { valid: [ @@ -354,52 +360,55 @@ describe(RULE_NAME, () => { ], }) - ruleTester.run( - `${RULE_NAME}(${type}): sorts all-exports only if export kind is value`, - rule, - { - valid: [ - { - code: dedent` - export { TetsuMizuhara } from './mizuhara' - export * as Kuromura from './kuromura' - export { SuzuHoujou } from './houjou' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - }, - ], - invalid: [ - { - code: dedent` - export * as Kuromura from './kuromura' - export { SuzuHoujou } from './houjou' - export { TetsuMizuhara } from './mizuhara' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - output: dedent` - export { TetsuMizuhara } from './mizuhara' - export * as Kuromura from './kuromura' - export { SuzuHoujou } from './houjou' - export * from 'hiroshima' - export { Shuusaku } from './shuusaku' - `, - options: [options], - errors: [ - { - messageId: 'unexpectedExportsOrder', - data: { - left: './houjou', - right: './mizuhara', - }, + ruleTester.run(`${RULE_NAME}(${type}): sorts all-exports`, rule, { + valid: [ + { + code: dedent` + export { TetsuMizuhara } from './mizuhara' + export * as Kuromura from './kuromura' + export { SuzuHoujou } from './houjou' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + }, + ], + invalid: [ + { + code: dedent` + export * as Kuromura from './kuromura' + export { SuzuHoujou } from './houjou' + export { TetsuMizuhara } from './mizuhara' + export * from 'hiroshima' + export { Shuusaku } from './shuusaku' + `, + output: dedent` + export { TetsuMizuhara } from './mizuhara' + export * as Kuromura from './kuromura' + export { SuzuHoujou } from './houjou' + export { Shuusaku } from './shuusaku' + export * from 'hiroshima' + `, + options: [options], + errors: [ + { + messageId: 'unexpectedExportsOrder', + data: { + left: './houjou', + right: './mizuhara', }, - ], - }, - ], - }, - ) + }, + { + messageId: 'unexpectedExportsOrder', + data: { + left: 'hiroshima', + right: './shuusaku', + }, + }, + ], + }, + ], + }) ruleTester.run(`${RULE_NAME}(${type}): works with export aliases`, rule, { valid: [