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

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': {

This comment has been minimized.

@ljharb

ljharb Aug 4, 2020
Collaborator

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.

This comment has been minimized.

@jzabala

jzabala Aug 4, 2020
Author Contributor

@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.

This comment has been minimized.

@ljharb

ljharb Aug 5, 2020
Collaborator

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

This comment has been minimized.

@jzabala

jzabala Aug 13, 2020
Author Contributor

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:

"prop-types": "^15.7.2",

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.

This comment has been minimized.

@ljharb

ljharb Aug 13, 2020
Collaborator

Hmm, that is a fair point on the prop-types dep.

This comment has been minimized.

@jzabala

jzabala Aug 13, 2020
Author Contributor

But we can still do it right.

The only rule that depends on prop-types is no-typos.

const PROP_TYPES = Object.keys(require('prop-types'));

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.

This comment has been minimized.

@ljharb

ljharb Aug 13, 2020
Collaborator

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 approved these changes Aug 13, 2020
@ljharb ljharb force-pushed the jzabala:feat/add-exact-proptypes-support branch from ac3d11a to 7850e57 Aug 13, 2020
@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 yannickcr:master Aug 13, 2020
2 checks passed
2 checks passed
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage remained the same at 97.473%
Details
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

2 participants
You can’t perform that action at this time.