From a0bf2eec3ee62bf6438b3de31a8df64ace93febf Mon Sep 17 00:00:00 2001 From: SukkaW Date: Wed, 30 Oct 2024 20:54:22 +0800 Subject: [PATCH] fix(no-named-as-default): add extra guards https://github.com/import-js/eslint-plugin-import/pull/3032 --- src/rules/no-named-as-default.ts | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/rules/no-named-as-default.ts b/src/rules/no-named-as-default.ts index 673f44e86..d2cd1190f 100644 --- a/src/rules/no-named-as-default.ts +++ b/src/rules/no-named-as-default.ts @@ -49,6 +49,17 @@ export = createRule<[], MessageId>({ return } + if (!exportMapOfImported.hasDefault) { + // The rule is triggered for default imports/exports, so if the imported module has no default + // this means we're dealing with incorrect source code anyway + return + } + + if (!exportMapOfImported.has(nameValue)) { + // The name used locally for the default import was not even used in the imported module. + return + } + if ( exportMapOfImported.exports.has('default') && exportMapOfImported.exports.has(nameValue)