From ad0238ad9f5ae01fa6072a34b7e07ebfffc1c647 Mon Sep 17 00:00:00 2001 From: Joao Date: Tue, 18 Feb 2020 17:13:52 +0100 Subject: [PATCH] Fix: [no-duplicate-imports] Treat namespace imports as different (fixes #12758) --- lib/rules/no-duplicate-imports.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/rules/no-duplicate-imports.js b/lib/rules/no-duplicate-imports.js index 7218dc64add..7ef3b37b978 100644 --- a/lib/rules/no-duplicate-imports.js +++ b/lib/rules/no-duplicate-imports.js @@ -21,6 +21,20 @@ function getValue(node) { return ""; } +/** + * Checks if the import's type is a namespace import. + * @param {ASTNode} node A node to get. + * + * @returns {boolean} Whether or not the import's type is "ImportNamespaceSpecifier". + */ +function isNamespaceImport(node) { + return ( + node.specifiers && + node.specifiers[0] && + node.specifiers[0].type === "ImportNamespaceSpecifier" + ); +} + /** * Checks if the name of the import or export exists in the given array, and reports if so. * @param {RuleContext} context The ESLint rule context object. @@ -61,7 +75,7 @@ function handleImports(context, includeExports, importsInFile, exportsInFile) { return function(node) { const value = getValue(node); - if (value) { + if (value && !isNamespaceImport(node)) { checkAndReport(context, node, value, importsInFile, "import"); if (includeExports) {