azat-io / eslint-plugin-perfectionist

🦄 ESLint plugin for sorting various data such as objects, imports, types, enums, JSX props, etc.
https://eslint-plugin-perfectionist.azat.io
MIT License
1.62k stars 28 forks source link

Bug: (sort-exports) does not work for 'export *' #119

Closed mqwerty closed 1 month ago

mqwerty commented 1 month ago

Describe the bug

sort-exports rule does not work for 'export *'

// .eslintrc.cjs
'perfectionist/sort-exports': [
  'error',
  {
    'type': 'alphabetical',
    'order': 'asc',
  },
],

Code example

export * from './b'
export * from './a' // <- There must be a error here

ESLint version

8.57.0

ESLint Plugin Perfectionist version

2.6.0

Additional comments

No response

Validations

snevolin commented 1 month ago

Just stumbled upon the problem, would really like a fix

azat-io commented 1 month ago

This is done for security reasons.

Example:

// a.js
export function func {
  return 1
}
// b.js
export function func {
  return 2
}

Depending on the priority, we will have different function values.

We intentionally do not sort exports with an * because there may be conflicts.

snevolin commented 1 month ago

Actually, this problem doesn’t exist in TypeScript because these conflicts are immediately visible. Maybe we could consider implementing sorting just for ts files?

azat-io commented 1 month ago

Could you please demonstrate what the conflicts look like in the TS files?

snevolin commented 1 month ago
// a.ts
export function func () {
  return 1
}
// b.ts
export function func () {
  return 2
}

And if you had put exports in index.ts like this

export * from './b'
export * from './a'

You'd get a TS error:

Module './b' has already exported a member named 'func'. Consider explicitly re-exporting to resolve the ambiguity.ts(2308)