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] prop-types: add support for PropTypes.exact #2740

Merged
merged 1 commit into from Aug 13, 2020

Conversation

jzabala
Copy link
Contributor

@jzabala jzabala commented Aug 3, 2020

Closes #2590

@@ -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': {
Copy link
Member

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.

Copy link
Contributor Author

@jzabala jzabala Aug 4, 2020

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.

Copy link
Member

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');.

Copy link
Contributor Author

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:

https://github.com/yannickcr/eslint-plugin-react/blob/d8741de74da0fb7a0cb730f0fea14de05e4faa9b/package.json#L39

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.

Copy link
Member

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.

Copy link
Contributor Author

@jzabala jzabala Aug 13, 2020

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.

https://github.com/yannickcr/eslint-plugin-react/blob/d8741de74da0fb7a0cb730f0fea14de05e4faa9b/lib/rules/no-typos.js#L7

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.

Copy link
Member

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.

@ljharb ljharb force-pushed the feat/add-exact-proptypes-support branch from ac3d11a to 7850e57 Compare August 13, 2020 18:59
@ljharb ljharb changed the title feat(propTypes-util): add support for PropTypes.exact [New] prop-types: add support for PropTypes.exact Aug 13, 2020
@ljharb ljharb merged commit 7850e57 into jsx-eslint:master Aug 13, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

prop-types does not recognize PropTypes.exact
2 participants