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

Code before:
            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 hasRestrictedNamePattern = false;

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

                hasRestrictedNamePattern = name && patternRegex.test(name);
            }

            if (hasRestrictedNamePattern || 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) {

Review comment (suggestion):
```suggestion
                hasRestrictedNamePattern = patternRegex.test(name);
```

At this point, `name` is certainly a string, and a falsy empty string name should also be checked against the pattern.

```js
/*eslint no-restricted-exports: ["error", {
    "restrictedNamedExportsPattern": "^$"
}]*/


const foo = 1;

export { foo as "" }; // false negative, it matces the pattern

```

Code after:
            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;
                    const specifierLocalName = astUtils.getModuleExportName(node.parent.local);

                    if (!isSourceSpecified && restrictDefaultExports && restrictDefaultExports.named) {