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

Issue#11510: added verification check for misspelled propTypes #11524

Merged
merged 11 commits into from
Nov 24, 2017
12 changes: 11 additions & 1 deletion packages/react/src/ReactElementValidator.js
Original file line number Diff line number Diff line change
Expand Up @@ -214,14 +214,24 @@ function validateChildKeys(node, parentType) {
*
* @param {ReactElement} element
*/
var propTypesMisspellWarningShown;
Copy link
Collaborator

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?

Copy link
Collaborator

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.

Copy link
Author

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.

Copy link
Author

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 and ReactJSXElementValidator-test?

Copy link
Collaborator

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.

Copy link
Author

@M-ZubairAhmed M-ZubairAhmed Nov 14, 2017

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)?

function validatePropTypes(element) {
var componentClass = element.type;
if (typeof componentClass !== 'function') {
return;
}
var name = componentClass.displayName || componentClass.name;
var propTypes = componentClass.propTypes;

if (
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe let's put it into an else clause to the next if?

if (propTypes) {
  // ...
} else if (componentClass.PropTypes && !propTypesMisspellWarningShown) {
  // ...
}

Copy link
Author

@M-ZubairAhmed M-ZubairAhmed Nov 14, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have also tested this in fixtures/dom by introducing some props and misspelling propTypes

componentClass.PropTypes !== undefined &&
!propTypesMisspellWarningShown
) {
propTypesMisspellWarningShown = true;
warning(
false,
'Static propTypes method should be accessed by `.propTypes = { }` instead of `.PropTypes = { }`',
Copy link
Collaborator

@gaearon gaearon Nov 13, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's reword to say:

Component %s declared `PropTypes` instead of `propTypes`. Did you misspell the property assignment?

And pass the component name name || 'Unknown' as an argument.

Copy link
Author

Choose a reason for hiding this comment

The 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);
Expand Down