-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
base: master
Are you sure you want to change the base?
Conversation
@ljharb what do you think? |
allowPatternList: typeof value === 'string' ? [] : value.allowedForPatterns || [], | ||
disallowList: typeof value === 'string' ? [] : (value.disallowedFor || []), | ||
disallowPatternList: typeof value === 'string' ? [] : value.disallowedForPatterns || [], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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?
function checkIsTagForbiddenByAllowList() { | ||
return options.allowList.indexOf(tagName) === -1; | ||
} |
There was a problem hiding this comment.
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.
function checkIsTagForbiddenByAllowPatternList() { | ||
if (options.allowPatternList.length === 0) { | ||
return true; | ||
} | ||
|
||
return options.allowPatternList.every( | ||
(pattern) => !minimatch(tagName, pattern) | ||
); | ||
} |
There was a problem hiding this comment.
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.
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(); | ||
} |
There was a problem hiding this comment.
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
Thanks a lot for the feedback, I will apply the changes. |
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 withglobs
as was suggested in one of the comments.