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 12, 2024
1 parent ac7356f commit 43f0a46
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions docs/src/rules/no-restricted-exports.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ Example of **incorrect** code for the `"restrictedNamedExportsPattern"` option:
export const foobar = 1;
```

:::

Example of **correct** code for the `"restrictedNamedExportsPattern"` option:

::: correct
Expand All @@ -157,6 +159,8 @@ Example of **correct** code for the `"restrictedNamedExportsPattern"` option:
export const abc = 1;
```

:::

### 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
6 changes: 3 additions & 3 deletions lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,15 +112,15 @@ module.exports = {
function checkExportedName(node) {
const name = astUtils.getModuleExportName(node);

let hasRestrictedNamePattern = false;
let matchesRestrictedNamePattern = false;

if (restrictedNamePattern) {
const patternRegex = new RegExp(restrictedNamePattern, "u");

hasRestrictedNamePattern = name && patternRegex.test(name);
matchesRestrictedNamePattern = patternRegex.test(name);
}

if (hasRestrictedNamePattern || restrictedNames.has(name)) {
if (matchesRestrictedNamePattern || restrictedNames.has(name)) {
context.report({
node,
messageId: "restrictedNamed",
Expand Down
11 changes: 11 additions & 0 deletions tests/lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,10 @@ ruleTester.run("no-restricted-exports", rule, {
code: "var setSomething; export { setSomething };",
options: [{ restrictedNamedExportsPattern: "^get" }]
},
{
code: "var foo, bar; export { foo, bar };",
options: [{ restrictedNamedExportsPattern: "^(?!foo)(?!bar).+$" }]
},

// does not check re-export all declarations
{ code: "export * from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
Expand Down Expand Up @@ -574,6 +578,13 @@ ruleTester.run("no-restricted-exports", rule, {
{ messageId: "restrictedNamed", data: { name: "privateUserEmail" }, type: "Identifier" }
]
},
{
code: "export const a = 1;",
options: [{ restrictedNamedExportsPattern: "^(?!foo)(?!bar).+$" }],
errors: [
{ messageId: "restrictedNamed", data: { name: "a" }, type: "Identifier" }
]
},

// reports "default" in named export declarations (when configured)
{
Expand Down

0 comments on commit 43f0a46

Please sign in to comment.