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

Code before:

        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") {
                if (node.parent.type === "ExportAllDeclaration") {
                    const isSourceSpecified = node.parent.source;

                    if (isSourceSpecified && 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({
                                node,

Review comment (suggestion):
```suggestion

                    if (restrictDefaultExports && restrictDefaultExports.namespaceFrom) {
```

I believe checking if the source is specified is redundant because ExportAllDeclaration must have the source.

Code after:

        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({
                                node,
                                messageId: "restrictedDefault"
                            });