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
Fix: [no-duplicate-imports] ignore namespace imports (fixes #12758) #12935
Conversation
/*eslint no-duplicate-imports: "error"*/ | ||
|
||
import * as Namespace from 'module'; | ||
import { merge } from 'module'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This behaviour doesn't fit the heuristic:
an import that can be merged with another is a duplicate of that other.
Namespace imports and named imports can be merged with default imports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for your feedback @G-Rath
I'll rework on it to fit this scenario
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for putting this pull request together. I think you may have the desired functionality reversed, but you're not too far off.
Don't worry about extracting isNamespaceImport()
into a general utility. That's something that can always be done later if we need it.
@JoaoDsv are you still working on this? |
@nzakas I had no time to work on it since your feedback, but I'd be happy to resume this PR next week if it sounds still relevant (and not too late) for you. |
Not too late at all. Just wanted to be sure we give you a chance to finish up before someone else takes this on. If you’re not able to look at it next week, please let us know. |
@JoaoDsv just checking if are you still working on this? Totally understand if not, just want to be sure. |
It looks like this pull request has been abandoned, so closing. Note: the issue this PR addresses is still accepted (#12758) so anyone who wants to work on implementing the change may do so and submit a separate PR. |
Prerequisites checklist
What is the purpose of this pull request? (put an "X" next to an item)
Solve this issue.
What changes did you make? (Give an overview)
Fix a bug on [no-duplicate-imports] rule.
It shouldn't throw an error when the duplicated import is a namespace import such as
import * as Namespace from 'module'
What did you do? Please include the actual source code causing the issue.
Fix a bug on [no-duplicate-imports] rule.
What did you expect to happen?
It shouldn't throw an error when the duplicated import is a namespace import such as
import * as namespace from 'module'
. Because namespace imports can't be merged.Example of correct code:
What actually happened? Please include the actual, raw output from ESLint.
It was considered as incorrect.
Is there anything you'd like reviewers to focus on?
I'm wondering if it could be helpful to extract
isNamespaceImport()
function's content inside an util. WDYT?Transforming it a bit to be more generic, it should look like this: