eslint: [no-duplicate-imports] Treat namespace imports as different
What rule do you want to change? no-duplicate-imports
Does this change cause the rule to produce more or fewer warnings? Reduces warnings.
How will the change be implemented? (New option, new default behavior, etc.)? Behavioural change, which could be either option controlled or new default behaviour. Prior art: TSLint.
Please provide some example code that this change will affect:
import * as parsers from '@src/parsers';
import { SpecificParser } from '@src/parsers';
What does the rule currently do for this code? Marks the imports as duplicates
What will the rule do after it’s changed? Not mark the imports as duplicates
Are you willing to submit a pull request to implement this change? Yes
The primary use I have for the above is with mocking in jest, such as here where I want to both use the parsers & also spy on them to test that specific ones are called.
While I can use destructuring, or reference off parsers
, the former won’t be understood by auto-importers (i.e TS & IDE), and the latter would be inconsistent to how I use the functions in the rest of the codebase.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 7
- Comments: 32 (23 by maintainers)
Commits related to this issue
- Fix: [no-duplicate-imports] Treat namespace imports as different (fixes #12758) — committed to JoaoDsv/eslint by deleted user 4 years ago
- Fix: no-duplicate-imports allow unmergeable (fixes #12758, fixes #12760) — committed to boutahlilsoufiane/eslint by boutahlilsoufiane 3 years ago
- Fix: no-duplicate-imports allow unmergeable (fixes #12758, fixes #12760) (#14238) * Fix: ignore unmergable imports when checking no-duplicate-imports (fixes #13180) & Fix: Ignore re-export all in no-... — committed to eslint/eslint by boutahlilsoufiane 3 years ago
This remains a bug with an open PR; please reopen. cc @mdjermanovic
This makes sense as a heuristic to me. 👍
I think this is reasonable since these two cannot be merged into one, so the rule at the moment indirectly disallows named imports if the namespace is imported.
This could be indeed user’s preference, but I’m not sure that such restriction was the intention of this particular rule.
Maybe this can be treated as a bug and become a new default behavior instead of an option?
I’m going to do this, give me two weeks.
Marking as accepted since three team members agree that this is a bug.
Hi @boutahlilsoufiane!
The tests for this change should be added to tests/lib/rules/no-duplicate-imports.js
Command to run the tests:
npm run test:cli tests/lib/rules/no-duplicate-imports.js
You can find more details about the tests here:
Per https://github.com/eslint/eslint/pull/12767#issuecomment-643496156, we should also address #12760 in this issue.
Solved in this PR. If someone can have a look 🙏
Working on this issue.
I agree, this seems like a bug.
imo this isn’t an enhancement, it’s a bug, and should be marked as such.