Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[New] forbid-component-props: add allowedForPatterns and disallowedForPatterns options #3805

Draft
wants to merge 10 commits into
base: master
Choose a base branch
from

Conversation

Efimenko
Copy link

@Efimenko Efimenko commented Aug 22, 2024

Initially, issue was described here, but it was closed by another PR (although this PR implements different case).
So, this PR just reimplements Regex implementation with globs as was suggested in one of the comments.

@Efimenko
Copy link
Author

@ljharb what do you think?

Comment on lines +145 to +147
allowPatternList: typeof value === 'string' ? [] : value.allowedForPatterns || [],
disallowList: typeof value === 'string' ? [] : (value.disallowedFor || []),
disallowPatternList: typeof value === 'string' ? [] : value.disallowedForPatterns || [],
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
allowPatternList: typeof value === 'string' ? [] : value.allowedForPatterns || [],
disallowList: typeof value === 'string' ? [] : (value.disallowedFor || []),
disallowPatternList: typeof value === 'string' ? [] : value.disallowedForPatterns || [],
allowPatternList: [].concat(value.allowedForPatterns || []),
disallowList: [].concat(value.disallowedFor || []),
disallowPatternList: [].concat(value.disallowedForPatterns || []),

altho i'm not sure why any of these would be able to be strings - doesn't the schema prevent that?

Comment on lines +172 to +174
function checkIsTagForbiddenByAllowList() {
return options.allowList.indexOf(tagName) === -1;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this seems overkill to make into a function, especially if it's used once. let's just inline it.

Comment on lines +176 to +184
function checkIsTagForbiddenByAllowPatternList() {
if (options.allowPatternList.length === 0) {
return true;
}

return options.allowPatternList.every(
(pattern) => !minimatch(tagName, pattern)
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

kind of same here? i'd rather checkIsTagForbiddenByAllowOptions be mutiline with some early returns.

Comment on lines +190 to +206
function checkIsTagForbiddenByDisallowList() {
return options.disallowList.indexOf(tagName) !== -1;
}

function checkIsTagForbiddenByDisallowPatternList() {
if (options.disallowPatternList.length === 0) {
return false;
}

return options.disallowPatternList.some(
(pattern) => minimatch(tagName, pattern)
);
}

function checkIsTagForbiddenByDisallowOptions() {
return checkIsTagForbiddenByDisallowList() || checkIsTagForbiddenByDisallowPatternList();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same feedback on these three functions

@ljharb ljharb marked this pull request as draft September 11, 2024 19:42
@Efimenko
Copy link
Author

Thanks a lot for the feedback, I will apply the changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging this pull request may close these issues.

2 participants