no-restricted-exports

禁止在导出中指定名称

在项目中,出于各种原因,某些名称可能不允许用作导出名称。

规则详情

此规则不允许将指定名称用作导出名称。

选项

默认情况下,此规则不允许任何名称。只有您在配置中指定的名称才会被禁止。

此规则有一个对象选项:

    l81LM1xDjtL6lBuzzK9i6VXwKE21gv1CKlnXJ1Qx2noxg2NpImLytf2XrApdC40SiNvaghZD8k1eSMeZpXv4Yv7RAR2zq775khFOEVqJSjVaTsTrNKlja0IgQpRNQw4JKjg7C9ZUgE8/rUgfD2Rs0WXuAj2ZtPFt+EK8zrzve24=

zblpFAyoEiDF1GS7EEgT+Fw+zDBsVLJNOcYSNQAXW6dSdz0JClE4rOOJ51S8csCM

/*eslint no-restricted-exports: ["error", {
    "restrictedNamedExports": ["foo", "bar", "Baz", "a", "b", "c", "d", "e", "👍"]
}]*/

export const foo = 1;

export function bar() {}

export class Baz {}

const a = {};
export { a };

function someFunction() {}
export { someFunction as b };

export { c } from "some_module";

export { "d" } from "some_module";

export { something as e } from "some_module";

export { "👍" } from "some_module";

h+1Jf/rEEE6yYiKhWnK/aHl9/UYIfowckm44qhmqvwwaWj0QX+JXnab7YJgxSmDw

/*eslint no-restricted-exports: ["error", {
    "restrictedNamedExports": ["foo", "bar", "Baz", "a", "b", "c", "d", "e", "👍"]
}]*/

export const quux = 1;

export function myFunction() {}

export class MyClass {}

const a = {};
export { a as myObject };

function someFunction() {}
export { someFunction };

export { c as someName } from "some_module";

export { "d" as " d " } from "some_module";

export { something } from "some_module";

export { "👍" as thumbsUp } from "some_module";

默认导出

zYE08P2s5Ie9TtopvsWYV6k5NEDCTsffhvXgqd79MLC4/C2oVyZDUsRHHbVjgrHp0zGfSs4/ZDcmfdqDemB8iyIsp/eevn9GejndyqrmfPqJ4M0eMX3FMxKAJauAzdMxeQQMk6L3tL6b2P9M8SCSB3A/7kNVW4FyrnI7qowo6VsG+cVQSXdoYsWqSbVRheSbepdVpi8OSskpHCqjHxY3J1qT467LRSe/+0P3MW1/PQitKrXp7xiQtmkp8AB0SBzR

2IOHnwdKwVcJZTotlv4JihJl+0oUU6A/OPE0RMn3DZTMYtubiIvE9NHAbQkHGVzl

/*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default"] }]*/

function foo() {}

export { foo as default };
/*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default"] }]*/

export { default } from "some_module";

6+ayNvUKqwylWGecWOX3Y09Cgg91w8kdz5kLQLS7Nl+wEINCnrXSXEoelHg+fwBm

/*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default", "foo"] }]*/

export default function foo() {}

已知限制

hio0/LjoaubtsN8Ed133b9sWnp6VE4LDXCIKNncEZAAhVvFQ4kWTICSHWeI+d2JVkbE7b15xCUWPXBnyP/tS/fhcosn38D1f+grYqH+rVNkJZipCffp8+H23hDnbeu/09I7Xm76fuGssklEoTJY71aWNzKz9/9cXK8pW9re7X6yO9cXKfWUJrlwuucOKfKzZW5JQKHJoi6gkg2sHMdgDtH5mdM+Vv7Qw69afnsiei/a8VSEBl48Qhrjseh34aP04MNIu2l2axXpe1Ghv27qa5JOP2/ovjTXJk8H/8a5eTw8=


//----- some_module.js -----
export function foo() {}

//----- my_module.js -----
/*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["foo"] }]*/

export * from "some_module"; // allowed, although this declaration exports "foo" from my_module