-
Notifications
You must be signed in to change notification settings - Fork 885
no-duplicate-imports: Allow duplicate imports from separate ambient module declarations #3398
Conversation
…odule declarations
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.
LGTM with a suggestion
src/rules/noDuplicateImportsRule.ts
Outdated
seen.add(text); | ||
} | ||
|
||
if (isModuleDeclaration(statement) && statement.body !== undefined && isModuleBlock(statement.body)) { |
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.
you could add an additional check here if statement.name.kind === ts.SyntaxKind.StringLiteral
, because namespaces cannot contain import statements.
and then you probably don't need the isModuleBlock
check.
src/rules/noDuplicateImportsRule.ts
Outdated
case ts.SyntaxKind.ImportDeclaration: | ||
return (statement as ts.ImportDeclaration).moduleSpecifier; | ||
case ts.SyntaxKind.ImportEqualsDeclaration: | ||
const ref = (statement as ts.ImportEqualsDeclaration).moduleReference; |
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.
It didn't check ImportEqualsDeclaration before your change. That's not a problem, but should be mentioned in the changelog.
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.
It was right before because you might want named imports from a module in addition to importing it as a function. Removed this part.
thanks @andy-ms |
@ajafff Could you make a release with these changes? |
@mxl I could prepare a release PR, but I cannot do the actual release. |
…odule declarations (palantir#3398)
PR checklist
Overview of change:
Allows two ambient modules to have separate imports:
Preserves existing behavior for module augmentations.
@ajafff It would be nice to reuse more code from
findImports
in tsutils but it doesn't seem possible given that it currently takes the whole source file as input, so I can't run it on a singledeclare module
.CHANGELOG.md entry:
[bugfix] no-duplicate-imports: Allow duplicate imports from separate ambient module declarations