]> git.proxmox.com Git - pve-eslint.git/blob - eslint/docs/src/rules/no-restricted-exports.md
import 8.23.1 source
[pve-eslint.git] / eslint / docs / src / rules / no-restricted-exports.md
1 ---
2 title: no-restricted-exports
3 layout: doc
4 rule_type: suggestion
5 ---
6
7
8 In a project, certain names may be disallowed from being used as exported names for various reasons.
9
10 ## Rule Details
11
12 This rule disallows specified names from being used as exported names.
13
14 ## Options
15
16 By default, this rule doesn't disallow any names. Only the names you specify in the configuration will be disallowed.
17
18 This rule has an object option:
19
20 * `"restrictedNamedExports"` is an array of strings, where each string is a name to be restricted.
21
22 Examples of **incorrect** code for this rule:
23
24 ::: incorrect
25
26 ```js
27 /*eslint no-restricted-exports: ["error", {
28 "restrictedNamedExports": ["foo", "bar", "Baz", "a", "b", "c", "d", "e", "👍"]
29 }]*/
30
31 export const foo = 1;
32
33 export function bar() {}
34
35 export class Baz {}
36
37 const a = {};
38 export { a };
39
40 function someFunction() {}
41 export { someFunction as b };
42
43 export { c } from "some_module";
44
45 export { "d" } from "some_module";
46
47 export { something as e } from "some_module";
48
49 export { "👍" } from "some_module";
50 ```
51
52 :::
53
54 Examples of **correct** code for this rule:
55
56 ::: correct
57
58 ```js
59 /*eslint no-restricted-exports: ["error", {
60 "restrictedNamedExports": ["foo", "bar", "Baz", "a", "b", "c", "d", "e", "👍"]
61 }]*/
62
63 export const quux = 1;
64
65 export function myFunction() {}
66
67 export class MyClass {}
68
69 const a = {};
70 export { a as myObject };
71
72 function someFunction() {}
73 export { someFunction };
74
75 export { c as someName } from "some_module";
76
77 export { "d" as " d " } from "some_module";
78
79 export { something } from "some_module";
80
81 export { "👍" as thumbsUp } from "some_module";
82 ```
83
84 :::
85
86 ### Default exports
87
88 By design, this rule doesn't disallow `export default` declarations. If you configure `"default"` as a restricted name, that restriction will apply only to named export declarations.
89
90 Examples of additional **incorrect** code for this rule:
91
92 ::: incorrect
93
94 ```js
95 /*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default"] }]*/
96
97 function foo() {}
98
99 export { foo as default };
100 ```
101
102 :::
103
104 ::: incorrect
105
106 ```js
107 /*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default"] }]*/
108
109 export { default } from "some_module";
110 ```
111
112 :::
113
114 Examples of additional **correct** code for this rule:
115
116 ::: correct
117
118 ```js
119 /*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["default", "foo"] }]*/
120
121 export default function foo() {}
122 ```
123
124 :::
125
126 ## Known Limitations
127
128 This rule doesn't inspect the content of source modules in re-export declarations. In particular, if you are re-exporting everything from another module's export, that export may include a restricted name. This rule cannot detect such cases.
129
130 ```js
131
132 //----- some_module.js -----
133 export function foo() {}
134
135 //----- my_module.js -----
136 /*eslint no-restricted-exports: ["error", { "restrictedNamedExports": ["foo"] }]*/
137
138 export * from "some_module"; // allowed, although this declaration exports "foo" from my_module
139 ```