Repository: eslint/eslint
File: lib/rules/no-restricted-exports.js (JavaScript)

Code before:
    },

    create(context) {

        const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports);
        const restrictDefaultExports = context.options[0] && !restrictedNames.has("default") && context.options[0].restrictDefaultExports;

        /**
         * Checks and reports given exported name.
         * @param {ASTNode} node exported `Identifier` or string `Literal` node to check.
         * @returns {void}
         */
        function checkExportedName(node) {
            const name = astUtils.getModuleExportName(node);

            if (restrictedNames.has(name)) {
                context.report({
                    node,
                    messageId: "restrictedNamed",
                    data: { name }
                });
                return;
            }

            if (name === "default") {
                const isSourceSpecified = node.parent.source || node.parent.parent.source;
                const specifierLocalName = node.parent.local && node.parent.local.name;

                if (!isSourceSpecified && restrictDefaultExports && restrictDefaultExports.named) {
                    context.report({
                        node,
                        messageId: "restrictedDefault"
                    });
                    return;
                }

                if (isSourceSpecified && restrictDefaultExports) {
                    if (
                        (specifierLocalName === "default" && restrictDefaultExports.defaultFrom) ||
                        (specifierLocalName !== "default" && restrictDefaultExports.namedFrom) ||
                        (node.parent.type === "ExportAllDeclaration" && restrictDefaultExports.namespaceFrom)
                    ) {
                        context.report({
                            node,
                            messageId: "restrictedDefault"
                        });
                    }
                }
            }
        }


Review comment (suggestion):
This is a bit difficult to follow, can we split the logic into two branches?

```js
if (node.parent.type === "ExportAllDeclaration") {
   // ...
} else { // ExportSpecifier
  // ...
}

```

Code after:
    },

    create(context) {

        const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports);
        const restrictDefaultExports = context.options[0] && context.options[0].restrictDefaultExports;

        /**
         * Checks and reports given exported name.
         * @param {ASTNode} node exported `Identifier` or string `Literal` node to check.
         * @returns {void}
         */
        function checkExportedName(node) {
            const name = astUtils.getModuleExportName(node);

            if (restrictedNames.has(name)) {
                context.report({
                    node,
                    messageId: "restrictedNamed",
                    data: { name }
                });
                return;
            }

            if (name === "default") {
                if (node.parent.type === "ExportAllDeclaration") {
                    if (restrictDefaultExports && restrictDefaultExports.namespaceFrom) {
                        context.report({
                            node,
                            messageId: "restrictedDefault"
                        });
                    }

                } else { // ExportSpecifier
                    const isSourceSpecified = !!node.parent.parent.source;
                    const specifierLocalName = astUtils.getModuleExportName(node.parent.local);

                    if (!isSourceSpecified && restrictDefaultExports && restrictDefaultExports.named) {
                        context.report({
                            node,
                            messageId: "restrictedDefault"
                        });
                        return;
                    }

                    if (isSourceSpecified && restrictDefaultExports) {
                        if (
                            (specifierLocalName === "default" && restrictDefaultExports.defaultFrom) ||
                            (specifierLocalName !== "default" && restrictDefaultExports.namedFrom)
                        ) {
                            context.report({