Skip to content

Commit

Permalink
chore: review changes
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 committed May 13, 2024
1 parent 43f0a46 commit 2984afd
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
4 changes: 3 additions & 1 deletion docs/src/rules/no-restricted-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ 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.
* `"restrictedNamedExportsPattern"` is a regex string, and any named export matching that pattern would be restricted.
* `"restrictedNamedExportsPattern"` is a string representing a regular expression pattern. Named exports matching this pattern will be restricted. This option does not apply to `default` named exports.
* `"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.
Expand Down Expand Up @@ -161,6 +161,8 @@ export const abc = 1;

:::

Note that this option does not apply to `export default` or any `default` named exports. If you want to also restrict `default` exports, use the `restrictDefaultExports` option.

### 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:
Expand Down
2 changes: 1 addition & 1 deletion lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ module.exports = {

let matchesRestrictedNamePattern = false;

if (restrictedNamePattern) {
if (restrictedNamePattern && name !== "default") {
const patternRegex = new RegExp(restrictedNamePattern, "u");

matchesRestrictedNamePattern = patternRegex.test(name);
Expand Down
4 changes: 4 additions & 0 deletions tests/lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,10 @@ ruleTester.run("no-restricted-exports", rule, {
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"] }] },
Expand Down

0 comments on commit 2984afd

Please sign in to comment.