-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feature request: add ignore options for import/no-duplicates
#1479
Comments
This seems like an inherent flaw in resolving a module to a d.ts file that might represent multiple files. I don’t think forcing an allowlist is an elegant solution; I’d prefer to find a better one. |
If we do have a better one, that will be greater. |
@ljharb Any news on this. If we don't have a better solution, an option for whitelist maybe considered? |
Rereading the OP, it kind of seems like it’s just a bug in date-fns’ typings file? |
Why do you think it's a bug of |
|
|
If the types in date-fns are correct, then I'm still confused what the issue is. Are you saying that because |
import * from 'date-fns'
import * from 'date-fns/locale' The above import statements both resolves a same declare module 'date-fns' {
// ...
}
declare module 'date-fns/locale' {
// ...
} |
Yes, that's the point. |
It doesn’t seem right to me that they should resolve to the location of their types, so that seems like something that should be fixed in the resolver. |
What's the problem of the resolver? We may import types from the pkg, there is no |
Yeah, i can see the difficulty. I’m not sure how we’d solve this properly. An exclude list seems like a workaround. |
So is this accepted? I can raise a PR if so. |
Given that most packages do the right thing, and don't ship types directly but rather use DT, and given that this is a potential problem with any package that chooses to conflate its API's semver with the semver of its types, I'd prefer to not add an exclude list and instead seek a true fix. |
So we need to support resolve |
I think that is the challenge, yes. |
Hi, we have the issue where
is merged into
Is there a way to avoid this since the last msg is from more than a year ago? |
Hi @wcastand, our workaround for this, until its solved, looks like this: /* eslint-disable import/no-duplicates */
import formatDate from 'date-fns/format'
import enGB from 'date-fns/locale/en-GB'
import de from 'date-fns/locale/de'
/* eslint-enable import/no-duplicates */ I hope this helps. |
yeah we went with a ignore next line on each line but it's not really a solution to me. thanks for sharing still :) |
This was my temporary solution:import { differenceInDays, format, startOfDay, startOfToday } from "date-fns";
import * as locale from "date-fns/locale";
...
const { ptBR } = locale; |
@manfrinmm that's my temporary solution: // locale/dateFns.ts
import ptBRLocale from 'date-fns/locale/pt-BR';
export { ptBRLocale };
// other files
import { ptBRLocale } from './locale/dateFns'; |
Another simple use-case: import format from 'date-fns/format';
import differenceInHours from 'date-fns/differenceInHours';
import orderBy from 'lodash/orderBy';
import get from 'lodash/get';
Would love to have an options to exclude some packages or patterns from the check |
A temporary workaround can be to use plugins: ['local'],
processor: 'local/suppress', Then, to create a module.exports = {
processors: {
suppress: {
postprocess: (messages) => {
const [message] = messages.map((violations) =>
violations.filter(
(violation) =>
!violation.message.endsWith(
"date-fns/typings.d.ts' imported multiple times."
)
)
)
return message
}
}
}
} But a proper support of it is still highly desirable. Either with an array of excludes, or a proper support on the resolver level. |
Same thing happens with
will be fixed to yield
|
Same problem here. Would love a resolution! This can probably be paired with eslint-import-resolver-typescript#197 as a 'refactor the way .d.ts modules are handled' issue |
You will meet this issue more often if custom |
Not if its properly supported |
I may do some prototypes on https://github.com/un-es/eslint-plugin-i |
The original post and title seems to be rather different from the problem we're all facing here. While an ignore list might be useful, the more pressing problem seems to be a request to fix this bug where multiple |
I agree, the description in this issue seems to reflect the problem we are having in this thread. Not sure why, but we are in the process of upgrading from Svelte 3 to Svelte 4, and now we are facing this error. Example: This is triggering a warning from the plugin, and is refactored when using fix. And it breaks the code. import { createEventDispatcher } from 'svelte';
import { writable } from 'svelte/store'; After fix: import { createEventDispatcher, writable } from 'svelte'; |
Yes, this issue started happening for me once I upgraded to Svelte 4. Maybe they changed their So it should be clear: this problem incorrectly acts in a way that breaks code (when auto-fixing is applied) for anyone using Svelte 4, among many other libraries, which choose to use valid TypeScript for |
I agree. I'm actually in the process of having to temporarily remove the usage of this ESLint plugin, to be able to upgrade to Svelte 4. |
You can just disable this specific check if you'd prefer: // Reenable once <https://github.com/import-js/eslint-plugin-import/issues/1479> is fixed.
"import/no-duplicates": "off", |
A workaround I found to is to fallback to the "import/no-duplicates": "off",
"no-duplicate-imports": "error", |
* npm install -D eslint-import-resolver-typescript eslint-plugin-import * add import rules * fix: add ignore comment for eslint-plugin-import bug. cf. import-js/eslint-plugin-import#1479 * eslint src/ --fix
* npm install -D eslint-import-resolver-typescript eslint-plugin-import * add import rules * fix: add ignore comment for eslint-plugin-import bug. cf. import-js/eslint-plugin-import#1479 * eslint src/ --fix Co-authored-by: Hiromasa Ihara <[email protected]>
When using TypeScript with date-fns, it only has one bundled
typings.d.ts
, so eslint-import-resolver-ts will resolve all modules to it.But they are not all exported from
date-fns
, what meansdate-fns
anddate-fns/locale
are different.So we should allow this case by whitelist.
The text was updated successfully, but these errors were encountered: