import-js / eslint-plugin-import

ESLint plugin with rules that help validate proper imports.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[import/no-duplicates] Autofix merges imports incorrectly - single index.d.ts but multiple modules

mpellegrini opened this issue · comments

Working on a Svelte project. For a majority of their packages, they have a single index.d.ts that is used but the d.ts file uses modules for namespacing.

Subset of the package.json exports

"./animate": {
      "types": "./types/index.d.ts",
      "default": "./src/runtime/animate/index.js"
    },
    "./easing": {
      "types": "./types/index.d.ts",
      "default": "./src/runtime/easing/index.js"
    },

so for the above fragment I have an imports that looks like this

  import { quadOut } from 'svelte/easing'
  import { crossfade } from 'svelte/transition'

This yields the following warning:

warning  '.../node_modules/.pnpm/svelte@4.2.12/node_modules/svelte/types/index.d.ts' imported multiple times  import/no-duplicates

but auto fix changes this to the following - which is not correct and doesn't work from a code perspective

  import { quadOut, crossfade } from 'svelte'

Trying to determine if there is any way to keep this rule but allow for exception to the rules.

Thanks in advance for any help / guidance.

Are you using eslint-import-resolver-typescript? Please share your config if that doesn't fix it.

Thanks for the quick reply. I am using eslint-import-resolver-typescript. If it helps I created a sample app that uses the standard create svelte app skeleton project.

https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue

config being used is here - https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue/blob/main/.eslintrc.cjs

The specific file that is exhibiting this behavior is here https://github.com/mpellegrini/eslint-import-plugin-no-duplicates-issue/blob/main/src/routes/%2Bpage.svelte#L2

I have already added the eslint disable on one of the imports that is auto fixing incorrectly.

For other types of imports it is working for me, bot collapsing and keeping things separate as expected. Just specifically with these imports from Svelte.

If there is anything else I can provide please let me know.