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

Code before:

        // does not check source in re-export declarations
        { code: "export { b } from 'a';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export * as b from 'a';", options: [{ restrictedNamedExports: ["a"] }] },

        // does not check non-export declarations
        { code: "var a;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "let a;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "const a = 1;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "function a() {}", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "class A {}", options: [{ restrictedNamedExports: ["A"] }] },
        { code: "import a from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "import { a } from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "import { b as a } from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        {
            code: "var setSomething; export { setSomething };",
            options: [{ restrictedNamedExportsPattern: "^get" }]
        },
        {
            code: "var foo, bar; export { foo, bar };",
            options: [{ restrictedNamedExportsPattern: "^(?!foo)(?!bar).+$" }]
        },
        {
            code: "var foobar; export default foobar;",
            options: [{ restrictedNamedExportsPattern: "bar$" }]
        },

        // does not check re-export all declarations
        { code: "export * from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export * from 'a';", options: [{ restrictedNamedExports: ["a"] }] },

        // does not mistakenly disallow identifiers in export default declarations (a default export will export "default" name)
        { code: "export default a;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export default function a() {}", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export default class A {}", options: [{ restrictedNamedExports: ["A"] }] },
        { code: "export default (function a() {});", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export default (class A {});", options: [{ restrictedNamedExports: ["A"] }] },

        // by design, restricted name "default" does not apply to default export declarations, although they do export the "default" name.
        { code: "export default 1;", options: [{ restrictedNamedExports: ["default"] }] },

        // "default" does not disallow re-exporting a renamed default export from another module
        { code: "export { default as a } from 'foo';", options: [{ restrictedNamedExports: ["default"] }] },

        // restrictDefaultExports.direct option
        { code: "export default foo;", options: [{ restrictDefaultExports: { direct: false } }] },
        { code: "export default 42;", options: [{ restrictDefaultExports: { direct: false } }] },
        { code: "export default function foo() {}", options: [{ restrictDefaultExports: { direct: false } }] },

        // restrictDefaultExports.named option
        { code: "const foo = 123;\nexport { foo as default };", options: [{ restrictDefaultExports: { named: false } }] },

Review comment (suggestion):
```suggestion
        {
            code: "var foobar; export default foobar;",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export default 'default';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "var foobar; export { foobar as default };",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "var foobar; export { foobar as 'default' };",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export { default } from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export { default as default } from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export { foobar as default } from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export * as default from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
```

Code after:

        // does not check source in re-export declarations
        { code: "export { b } from 'a';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "export * as b from 'a';", options: [{ restrictedNamedExports: ["a"] }] },

        // does not check non-export declarations
        { code: "var a;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "let a;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "const a = 1;", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "function a() {}", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "class A {}", options: [{ restrictedNamedExports: ["A"] }] },
        { code: "import a from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "import { a } from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        { code: "import { b as a } from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
        {
            code: "var setSomething; export { setSomething };",
            options: [{ restrictedNamedExportsPattern: "^get" }]
        },
        {
            code: "var foo, bar; export { foo, bar };",
            options: [{ restrictedNamedExportsPattern: "^(?!foo)(?!bar).+$" }]
        },
        {
            code: "var foobar; export default foobar;",
            options: [{ restrictedNamedExportsPattern: "bar$" }]
        },
        {
            code: "var foobar; export default foobar;",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export default 'default';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "var foobar; export { foobar as default };",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "var foobar; export { foobar as 'default' };",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export { default } from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {
            code: "export { default as default } from 'mod';",
            options: [{ restrictedNamedExportsPattern: "default" }]
        },
        {