Skip to content

Commit

Permalink
[Refactor] no-default-export: tweak rule
Browse files Browse the repository at this point in the history
  • Loading branch information
ljharb committed Nov 10, 2021
1 parent 7c239fe commit ceb5fe1
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions src/rules/no-default-export.js
Expand Up @@ -16,22 +16,18 @@ module.exports = {
}

const preferNamed = 'Prefer named exports.';
const noAliasDefault = ({ local }) =>
`Do not alias \`${local.name}\` as \`default\`. Just export ` +
`\`${local.name}\` itself instead.`;
const noAliasDefault = ({ local }) => `Do not alias \`${local.name}\` as \`default\`. Just export \`${local.name}\` itself instead.`;

return {
ExportDefaultDeclaration(node) {
context.report({ node, message: preferNamed });
},

ExportNamedDeclaration(node) {
node.specifiers.forEach(specifier => {
if (specifier.type === 'ExportDefaultSpecifier' &&
specifier.exported.name === 'default') {
node.specifiers.filter(specifier => specifier.exported.name === 'default').forEach(specifier => {
if (specifier.type === 'ExportDefaultSpecifier') {
context.report({ node, message: preferNamed });
} else if (specifier.type === 'ExportSpecifier' &&
specifier.exported.name === 'default') {
} else if (specifier.type === 'ExportSpecifier') {
context.report({ node, message: noAliasDefault(specifier) });
}
});
Expand Down

0 comments on commit ceb5fe1

Please sign in to comment.