Skip to content

Commit

Permalink
chore: update option name
Browse files Browse the repository at this point in the history
  • Loading branch information
akulsr0 committed May 8, 2024
1 parent 965754e commit aa547b9
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 7 deletions.
18 changes: 16 additions & 2 deletions lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,19 @@ module.exports = {
},
additionalProperties: false
},
{
type: "object",
properties: {
restrictedNamedExportsPattern: {
type: "array",
items: {
type: "string"
},
uniqueItems: true
}
},
additionalProperties: false
},
{
type: "object",
properties: {
Expand Down Expand Up @@ -100,6 +113,7 @@ module.exports = {
create(context) {

const restrictedNames = new Set(context.options[0] && context.options[0].restrictedNamedExports);
const restrictedNamePatterns = context.options[0] && context.options[0].restrictedNamedExportsPattern || [];
const restrictDefaultExports = context.options[0] && context.options[0].restrictDefaultExports;
const sourceCode = context.sourceCode;

Expand All @@ -111,9 +125,9 @@ module.exports = {
function checkExportedName(node) {
const name = astUtils.getModuleExportName(node);

const hasRestrictedName = [...restrictedNames].some(restrictedName => name === restrictedName || (name && minimatch(name, restrictedName)));
const hasRestrictedNamePattern = restrictedNamePatterns.some(pattern => name && minimatch(name, pattern));

if (hasRestrictedName) {
if (hasRestrictedNamePattern || restrictedNames.has(name)) {
context.report({
node,
messageId: "restrictedNamed",
Expand Down
12 changes: 7 additions & 5 deletions tests/lib/rules/no-restricted-exports.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ ruleTester.run("no-restricted-exports", rule, {
{ code: "import { b as a } from 'foo';", options: [{ restrictedNamedExports: ["a"] }] },
{
code: "var setSomething; export { setSomething };",
options: [{ restrictedNamedExports: ["get*"] }]
options: [{ restrictedNamedExportsPattern: ["get*"] }]
},

// does not check re-export all declarations
Expand Down Expand Up @@ -536,31 +536,33 @@ ruleTester.run("no-restricted-exports", rule, {
{ messageId: "restrictedNamed", data: { name: "f" }, type: "Identifier" }
]
},

// restrictedNamedExportsPattern
{
code: "var getSomething; export { getSomething };",
options: [{ restrictedNamedExports: ["get*"] }],
options: [{ restrictedNamedExportsPattern: ["get*"] }],
errors: [
{ messageId: "restrictedNamed", data: { name: "getSomething" }, type: "Identifier" }
]
},
{
code: "var getSomethingFromUser; export { getSomethingFromUser };",
options: [{ restrictedNamedExports: ["*User"] }],
options: [{ restrictedNamedExportsPattern: ["*User"] }],
errors: [
{ messageId: "restrictedNamed", data: { name: "getSomethingFromUser" }, type: "Identifier" }
]
},
{
code: "var foo, ab, xy; export { foo, ab, xy };",
options: [{ restrictedNamedExports: ["*+(b|y)"] }],
options: [{ restrictedNamedExportsPattern: ["*+(b|y)"] }],
errors: [
{ messageId: "restrictedNamed", data: { name: "ab" }, type: "Identifier" },
{ messageId: "restrictedNamed", data: { name: "xy" }, type: "Identifier" }
]
},
{
code: "var foo; export { foo as ab };",
options: [{ restrictedNamedExports: ["*+(b|y)"] }],
options: [{ restrictedNamedExportsPattern: ["*+(b|y)"] }],
errors: [
{ messageId: "restrictedNamed", data: { name: "ab" }, type: "Identifier" }
]
Expand Down

0 comments on commit aa547b9

Please sign in to comment.