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] prop-types
: add support for PropTypes.exact
#2740
[New] prop-types
: add support for PropTypes.exact
#2740
Conversation
@@ -422,13 +422,14 @@ module.exports = function propTypesInstructions(context, components, utils) { | |||
const callName = value.callee.property.name; | |||
const argument = value.arguments[0]; | |||
switch (callName) { | |||
case 'shape': { | |||
case 'shape': | |||
case 'exact': { |
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 don't think this should be included here - i think it should be a default member of propWrapperFunctions
. Otherwise, how can you turn it off?
Also, when the installed prop-types
package doesn't have exact
, it should not be supported.
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.
@ljharb
But why we would turn it off? exact
has been part of the library since 2017 from what I see.
About validating that prop-types
is installed, that would make us more correct but is not like React.PropTypes.exact
is going to work anyway. In that case the user would get a ReferenceError
on exact
, I think.
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.
Because someone might be using an older version of the library. There's lots of precedent; this plugin dynamically looks up the keys on require('prop-types')
in order to determine what's available.
React.PropTypes.exact
might work if a) the pragma isn't "React", b) they'd done React.PropTypes = require('prop-types');
.
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.
Because someone might be using an older version of the library. There's lots of precedent; this plugin dynamically looks up the keys on require('prop-types') in order to determine what's available.
Yeah, but the rule no-types
works the user having the library installed or not since this project already has it as a dependency:
Doing as suggested in comment #2590 (comment) would result in exact
always being included since the library would always resolve to the internal version of prop-types
.
React.PropTypes.exact might work if a) the pragma isn't "React", b) they'd done React.PropTypes = require('prop-types');
Added two more tests for this cases.
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.
Hmm, that is a fair point on the prop-types dep.
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.
But we can still do it right.
The only rule that depends on prop-types
is no-typos
.
So, to correctly feature detect exact
what do you think if I change prop-types
to a dev dependency, check for the existent of prop-types
before requiring it and fix no-typos
to not validate prop-types
names if the lib is not present.
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.
The intention in no-typos is that when new validators are added, they're suggested by default, without needing a change in this library.
ac3d11a
to
7850e57
Compare
prop-types
: add support for PropTypes.exact
Closes #2590