]> git.proxmox.com Git - pve-eslint.git/blobdiff - eslint/docs/src/rules/no-restricted-exports.md
import 8.41.0 source
[pve-eslint.git] / eslint / docs / src / rules / no-restricted-exports.md
index b1b20657edaff9c2bb8549e9be0566efb4154a17..2f83643f9cb8f0a2318173b61bb3b29d8376ec16 100644 (file)
@@ -1,6 +1,5 @@
 ---
 title: no-restricted-exports
-layout: doc
 rule_type: suggestion
 ---
 
@@ -18,8 +17,16 @@ By default, this rule doesn't disallow any names. Only the names you specify in
 This rule has an object option:
 
 * `"restrictedNamedExports"` is an array of strings, where each string is a name to be restricted.
+* `"restrictDefaultExports"` is an object option with boolean properties to restrict certain default export declarations. The option works only if the `restrictedNamedExports` option does not contain the `"default"` value. The following properties are allowed:
+    * `direct`: restricts `export default` declarations.
+    * `named`: restricts `export { foo as default };` declarations.
+    * `defaultFrom`: restricts `export { default } from 'foo';` declarations.
+    * `namedFrom`: restricts `export { foo as default } from 'foo';` declarations.
+    * `namespaceFrom`: restricts `export * as default from 'foo';` declarations.
 
-Examples of **incorrect** code for this rule:
+### restrictedNamedExports
+
+Examples of **incorrect** code for the `"restrictedNamedExports"` option:
 
 ::: incorrect
 
@@ -51,7 +58,7 @@ export { "👍" } from "some_module";
 
 :::
 
-Examples of **correct** code for this rule:
+Examples of **correct** code for the `"restrictedNamedExports"` option:
 
 ::: correct
 
@@ -83,11 +90,11 @@ export { "👍" as thumbsUp } from "some_module";
 
 :::
 
-### Default exports
+#### Default exports
 
-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.
+By design, the `"restrictedNamedExports"` option doesn't disallow `export default` declarations. If you configure `"default"` as a restricted name, that restriction will apply only to named export declarations.
 
-Examples of additional **incorrect** code for this rule:
+Examples of additional **incorrect** code for the `"restrictedNamedExports": ["default"]` option:
 
 ::: incorrect
 
@@ -111,7 +118,7 @@ export { default } from "some_module";
 
 :::
 
-Examples of additional **correct** code for this rule:
+Examples of additional **correct** code for the `"restrictedNamedExports": ["default"]` option:
 
 ::: correct
 
@@ -123,6 +130,85 @@ export default function foo() {}
 
 :::
 
+### restrictDefaultExports
+
+This option allows you to restrict certain `default` declarations. The option works only if the `restrictedNamedExports` option does not contain the `"default"` value. This option accepts the following properties:
+
+#### direct
+
+Examples of **incorrect** code for the `"restrictDefaultExports": { "direct": true }` option:
+
+::: incorrect
+
+```js
+/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "direct": true } }]*/
+
+export default foo;
+export default 42;
+export default function foo() {}
+```
+
+:::
+
+#### named
+
+Examples of **incorrect** code for the `"restrictDefaultExports": { "named": true }` option:
+
+::: incorrect
+
+```js
+/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "named": true } }]*/
+
+const foo = 123;
+
+export { foo as default };
+```
+
+:::
+
+#### defaultFrom
+
+Examples of **incorrect** code for the `"restrictDefaultExports": { "defaultFrom": true }` option:
+
+::: incorrect
+
+```js
+/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "defaultFrom": true } }]*/
+
+export { default } from 'foo';
+export { default as default } from 'foo';
+```
+
+:::
+
+#### namedFrom
+
+Examples of **incorrect** code for the `"restrictDefaultExports": { "namedFrom": true }` option:
+
+::: incorrect
+
+```js
+/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "namedFrom": true } }]*/
+
+export { foo as default } from 'foo';
+```
+
+:::
+
+#### namespaceFrom
+
+Examples of **incorrect** code for the `"restrictDefaultExports": { "namespaceFrom": true }` option:
+
+::: incorrect
+
+```js
+/*eslint no-restricted-exports: ["error", { "restrictDefaultExports": { "namespaceFrom": true } }]*/
+
+export * as default from 'foo';
+```
+
+:::
+
 ## Known Limitations
 
 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.