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

Code before:
        }],

        messages: {
            restrictedNamed: "'{{name}}' is restricted from being used as an exported name.",
            restrictedDefault: "Exporting 'default' is restricted."
        }
    },

    create(context) {

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

        /**
         * 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);

            let matchesRestrictedNamePattern = false;

            if (restrictedNamePattern) {
                const patternRegex = new RegExp(restrictedNamePattern, "u");

                matchesRestrictedNamePattern = patternRegex.test(name);
            }

            if (matchesRestrictedNamePattern || 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;

Review comment (suggestion):
```suggestion
            if (restrictedNamePattern && name !== "default") {
```

I think this is the only code change needed, but we should also add a few tests.

Code after:
        }],

        messages: {
            restrictedNamed: "'{{name}}' is restricted from being used as an exported name.",
            restrictedDefault: "Exporting 'default' is restricted."
        }
    },

    create(context) {

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

        /**
         * 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);

            let matchesRestrictedNamePattern = false;

            if (restrictedNamePattern && name !== "default") {
                const patternRegex = new RegExp(restrictedNamePattern, "u");

                matchesRestrictedNamePattern = patternRegex.test(name);
            }

            if (matchesRestrictedNamePattern || 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;