Skip to content

Commit

Permalink
[New] no-named-as-default: ignore if imported obj is exported both …
Browse files Browse the repository at this point in the history
…as default and named
  • Loading branch information
akwodkiewicz committed Aug 31, 2024
1 parent 53f46a9 commit 48fe865
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/rules/no-named-as-default.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,15 @@ module.exports = {

create(context) {
function checkDefault(nameKey, defaultSpecifier) {

/**
* For ImportDefaultSpecifier we're interested in the "local" name (`foo` for `import {bar as foo} ...`)
* For ExportDefaultSpecifier we're interested in the "exported" name (`foo` for `export {bar as foo} ...`)
*/
const analyzedName = defaultSpecifier[nameKey].name;

// #566: default is a valid specifier
if (defaultSpecifier[nameKey].name === 'default') { return; }
if (analyzedName === 'default') { return; }

const declaration = importDeclaration(context);

Expand All @@ -28,7 +35,15 @@ module.exports = {
return;
}

if (imports.has('default') && imports.has(defaultSpecifier[nameKey].name)) {
if (imports.has('default') && imports.has(analyzedName)) {

// #1594: the imported module exports the same thing via a default export and a named export
const namedExportInImportedModule = imports.reexports.get(analyzedName);
const defaultExportInImportedModule = imports.reexports.get('default');
if (defaultExportInImportedModule.getImport().path === namedExportInImportedModule.getImport().path
&& defaultExportInImportedModule.local === namedExportInImportedModule.local) {
return;
}

context.report(
defaultSpecifier,
Expand Down

0 comments on commit 48fe865

Please sign in to comment.