-
-
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] prop-types
: add support for PropTypes.exact
#2740
Merged
ljharb
merged 1 commit into
jsx-eslint:master
from
jzabala:feat/add-exact-proptypes-support
Aug 13, 2020
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 haveexact
, 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 likeReact.PropTypes.exact
is going to work anyway. In that case the user would get aReferenceError
onexact
, 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 doneReact.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.
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 ofprop-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
isno-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 changeprop-types
to a dev dependency, check for the existent ofprop-types
before requiring it and fixno-typos
to not validateprop-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.