Skip to content
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

import/no-duplicates false positives for TypeScript module declarations #2273

Closed
remcohaszing opened this issue Oct 26, 2021 · 1 comment · Fixed by #2378
Closed

import/no-duplicates false positives for TypeScript module declarations #2273

remcohaszing opened this issue Oct 26, 2021 · 1 comment · Fixed by #2378

Comments

@remcohaszing
Copy link
Contributor

The import/no-duplicates rule gives false positives for imports inside TypeScript module declarations.

Practical example:

declare module 'monaco-editor/esm/vs/editor/contrib/documentSymbols/documentSymbols' {
  import { ITextModel, languages } from 'monaco-editor';
}

declare module 'monaco-editor/esm/vs/editor/editor.worker' {
  import { worker } from 'monaco-editor';
}

This is happening, because import/no-duplicates collects all import statements and assumes they are in the program body.

I would expect the import/no-duplicates rule to be applied to each body separately. Currently these are the Program body and the TSModuleBlock body, but who knows what the future holds.

Alternatively the rule could be applied to imports which are direct children Program body only.

This is the same as #2217, but for a different rule. This means I can probably fix this if it gets accepted. :)

@ljharb
Copy link
Member

ljharb commented Oct 26, 2021

Ideally, the no-duplicates rule runs once for each of:

  • the file itself, omitting any declare blocks
  • each declare block

This refactoring will be useful if the "module blocks" language proposal advances, as well.

remcohaszing added a commit to remcohaszing/eslint-plugin-import that referenced this issue Jan 29, 2022
… module declarations

Without this the `import/no-duplicates` rule reports imports of the same
module inside different module declarations in the same file. It even
autofixed them, which break the code.

Closes import-js#2273
remcohaszing added a commit to remcohaszing/eslint-plugin-import that referenced this issue Feb 2, 2022
… module declarations

Without this the `import/no-duplicates` rule reports imports of the same
module inside different module declarations in the same file. It even
autofixed them, which break the code.

Closes import-js#2273
@ljharb ljharb closed this as completed in 0595a2f Feb 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
2 participants