-
-
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
Add support for propTypes wrapped in a function #1253
Conversation
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.
Thanks!
However, this behavior should be behind an option (array of strings), and that option should include an explicit identifier name for that function - ie, this should not be considered unless forbidExtraProps
is in the eslint config.
Is this what you had in mind? |
lib/rules/no-unused-prop-types.js
Outdated
@@ -44,6 +44,9 @@ module.exports = { | |||
}, | |||
skipShapeProps: { | |||
type: 'boolean' | |||
}, | |||
extraPropsFunc: { |
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.
i think this would be better as an array of unique strings - that way multiples could be provided.
Let's also rename it to "propWrapperFunctions"
Ok, I think it's ready for another pass :) |
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.
LGTM pending an update to the docs :-)
lib/rules/no-unused-prop-types.js
Outdated
type: 'string' | ||
propWrapperFunctions: { | ||
type: 'array', | ||
items: { |
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.
please add uniqueItems: true
so that jsonschema enforces uniqueness
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.
LGTM!
It'd be nice to rebase this down to a single commit.
4bda7e4
to
a71b3a7
Compare
👍 rebased. Thanks for the quick feedback. |
lib/rules/no-unused-prop-types.js
Outdated
case 'CallExpression': | ||
if ( | ||
configuration.propWrapperFunctions && | ||
configuration.propWrapperFunctions.indexOf(propTypes.callee.name) !== -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.
It might be worth converting the propWrapperFunctions to a structure with constant time lookup, like a Set, to keep this path fast.
lib/rules/no-unused-prop-types.js
Outdated
case 'CallExpression': | ||
if ( | ||
configuration.propWrapperFunctions && | ||
configuration.propWrapperFunctions.indexOf(propTypes.callee.name) !== -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.
that's a really great point. this should definitely be converted to a Set.
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.
Ok, updated
1520791
to
5d05311
Compare
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.
Almost there :-)
lib/rules/no-unused-prop-types.js
Outdated
@@ -56,6 +63,9 @@ module.exports = { | |||
var configuration = Object.assign({}, defaults, context.options[0] || {}); | |||
var skipShapeProps = configuration.skipShapeProps; | |||
var customValidators = configuration.customValidators || []; | |||
var propWrapperFunctions = configuration.propWrapperFunctions ? | |||
new Set(configuration.propWrapperFunctions) : new Set(); |
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.
var propWrapperFunctions = new Set(configuration.propWrapperFunctions || []);
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.
Dargh, thanks...should have caught that one
5d05311
to
57b974c
Compare
PropTypes would previously get ignored if wrapped in forbidExtraProps.
57b974c
to
5770f29
Compare
@dustinsoftware are there other rules that could benefit from this information? If so, maybe we should move it to "settings", and read from it in multiple rules? |
Has it been published? |
Nope, not yet. |
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.
LGTM
PropTypes would previously get ignored if wrapped in forbidExtraProps.