antfu/eslint-config

Duplicate imports are not fixed anymore in v4.14.0+

Closed this issue · 7 comments

Describe the bug

Recent release dropped eslint-plugin-import-x plugin with following commit message :

Consider we don't really use a lot feature from import-x, while it's rather heavy and recently introduced some binary package. I think it's better to avoid using it and keep this config lightweight and more portable.

  • import/consistent-type-specifier-style -> ts/consistent-type-imports
  • import/no-duplicates -> antfu/import-dedupe
  • import/newline-after-import -> style/padding-line-between-statements

for the other rules, I found their are not always strictly necessary. I am trying to remove them and see how it would affect the DX, and might bring back some of them if needed.

I think there has been confusion between no-duplicates & dedupe :

  • import/no-duplicates reports/fixes error when resolved paths are imported more than once
  • antfu/import-dedupe reports/fixes error when named imports are found more than once in a single import statement.

Therefore, removing the eslint-plugin-import-x plugin, actually dropped entirely the no-duplicates rule that aimed to merge imports statements to prevent duplicates, see failing CI in my reproduction link.

Am I missing something ?

Reproduction

I have some configuration that extends @antfu/eslint-config with minimal extra (mostly how imports are sorted) here :
https://github.com/kevinmarrec/cloudstack/blob/upgrade-antfu-eslint-config/packages/eslint-config/src/index.ts

With some unit testing to test sorts order (and also fixing duplicates) :
https://github.com/kevinmarrec/cloudstack/blob/upgrade-antfu-eslint-config/packages/eslint-config/test/config.test.ts#L23

Unfortunately with last release, it's not fixing duplicates anymore, here's a attempt within a PR :
kevinmarrec/cloudstack#50

Check CI (Github Action) for results :

Image

Workaround

My workaround is adding the plugin back and only enabling the rule I'm missing (import/no-duplicates) :

kevinmarrec/cloudstack@upgrade-antfu-eslint-config...upgrade-antfu-eslint-config-workaround

Solutions

I know that the configuration is highly opinionated, but should also very customizable, and I think we dropped some customization.

I wish that https://github.com/antfu/eslint-plugin-antfu could have a built-in antfu/no-duplicates rule that just re-exports the one from eslint-plugin-import-x.

When you look closely at it it's kind of a heavy rule that is hard to re-write, as it handles a lot of stuff, including interesting options like prefer-inline.

Also just let me know if the drop of this customization has room for improvement to put it back, or if I should follow the opinion and stick with the workaround of using back the plugin-import-x plugin ourselves.

Thanks !

System Info

System:
    OS: Linux 5.15 Ubuntu 24.04.2 LTS 24.04.2 LTS (Noble Numbat)
    CPU: (20) x64 13th Gen Intel(R) Core(TM) i7-13700H
    Memory: 12.83 GB / 15.43 GB
    Container: Yes
    Shell: 5.9 - /usr/bin/zsh
  Binaries:
    Node: 22.15.0 - ~/.nvm/versions/node/v22.15.0/bin/node
    Yarn: 1.22.22 - ~/.nvm/versions/node/v22.15.0/bin/yarn
    npm: 10.9.2 - ~/.nvm/versions/node/v22.15.0/bin/npm
    pnpm: 10.11.0 - ~/.nvm/versions/node/v22.15.0/bin/pnpm
    bun: 1.2.15 - ~/.bun/bin/bun

Used Package Manager

bun v1.2.15

Validations

  • Follow our Code of Conduct
  • Read the Contributing Guide.
  • Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
  • Check that this is a concrete bug. For Q&A, please open a GitHub Discussion instead.
  • The provided reproduction is a minimal reproducible of the bug.

Updated description with workaround, and question about if there's room for improvement or simply stick with opinion.

I found no-duplicate-imports in eslint/js, maybe that's what we need.

update: this rule is NOT fixable.

@9romise Not fixable and not suitable when dealing with types imports in TypeScript :)

I hope bringing the import plugin back can be considered. In my situation, these are the rules I found the most useful for maintaining consistency:

  1. import/first
  2. import/consistent-type-specifier-style
  3. import/newline-after-import
  4. import/no-default-export

I've ported some rules from eslint-plugin-import-x to a new package. (Others are still in progress)
Feel free to drop over to this repository and share more of your ideas.

@9romise Thanks for working on it! Looking forward to adapting to your package. It's indeed some valuable rules in the import plugin, but many of them are not actually coupled with the resolver. Feel free to PR when you free it's ready to try, thanks!

@9romise Thank you very much for your work, just upgraded to 4.15.0 and it worked smoothly.