-
Notifications
You must be signed in to change notification settings - Fork 47.5k
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
Issue#11510: added verification check for misspelled propTypes #11524
Changes from 2 commits
ec5279a
5f39533
4eaae3d
e297922
f381561
0b557d9
c39a009
dddcf9b
6d15d49
601bec9
e71096a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -214,14 +214,24 @@ function validateChildKeys(node, parentType) { | |
* | ||
* @param {ReactElement} element | ||
*/ | ||
var propTypesMisspellWarningShown; | ||
function validatePropTypes(element) { | ||
var componentClass = element.type; | ||
if (typeof componentClass !== 'function') { | ||
return; | ||
} | ||
var name = componentClass.displayName || componentClass.name; | ||
var propTypes = componentClass.propTypes; | ||
|
||
if ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe let's put it into an if (propTypes) {
// ...
} else if (componentClass.PropTypes && !propTypesMisspellWarningShown) {
// ...
} There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I have also tested this in |
||
componentClass.PropTypes !== undefined && | ||
!propTypesMisspellWarningShown | ||
) { | ||
propTypesMisspellWarningShown = true; | ||
warning( | ||
false, | ||
'Static propTypes method should be accessed by `.propTypes = { }` instead of `.PropTypes = { }`', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Let's reword to say:
And pass the component name There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. changes done. Thank you @gaearon for being so patient with me. |
||
); | ||
} | ||
if (propTypes) { | ||
currentlyValidatingElement = element; | ||
checkPropTypes(propTypes, element.props, 'prop', name, getStackAddendum); | ||
|
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.
Can we move this up to other DEV only variables?
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.
Also let's initialise it to false.
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.
Added the variable declaration under
if(__DEV__){
which is after import statements. Now working on test.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.
Should the test be added in both
ReactElementValidator-test
andReactJSXElementValidator-test
?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 just one is fine.
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.
Oh i just added test in both of them, i pushed my code. Should i remove from one ?
Also i have verified all tests were passing and ran build in my local example which was reproducing the error.
I was wondering if i should add another test it(
should not show any errors is correct propTypes property assignment is passed)
?