-
-
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
react/prop-types does not validate missing propTypes for functions in version 7.11.1 #1958
Comments
cc @alexzherdev |
@blackbird91 do you mean propTypes for functional components? Those are covered with tests pretty well, would you mind posting the code for the component that is having issues? |
@alexzherdev what about |
|
That's my example where props are not validated:
|
@blackbird91 hm, the rule might not be covering misusing a static getter in that fashion; if you make it |
It was working just fine in previous versions. Also, If I'm missing propTypes for other types of objects I get a validation message |
This exact code is reporting a missing prop as a test case. const { func } = this.props;
func(); |
@blackbird91 please provide text, not screenshots - screenshots of code aren't nearly as helpful :-/ |
I can't provide blocks of code, the small example I've posted before is very similar with the one I encounter in my project. I just wanted to show the difference between the 2 versions with these screen captures |
Also having the same issue. It seems to be related to components which spread props. A minimal example, for me, is the following: Working (has a linting error): class Component extends React.PureComponent {
render() {
this.props.doesNotExist(); // `react/no-props` linting error
return <div />;
}
} Not working (has no linting error): class Component extends React.PureComponent {
render() {
this.props.doesNotExist(); // No linting error
return <div {...this.props} />;
}
} |
@blackbird91 can you also post your render method? |
A simple case that was caught in 7.10.0 & not caught by 7.11.1 import React from 'react';
export default class TestComponent extends React.Component {
render() {
const { prop, ...rest } = this.props;
return <p {...rest}>{prop}</p>;
}
} 7.10.0 output:
7.11.1 output shows no errors. |
I'm seeing the same (or same-ish) issue with const Component = ({ prop }) => <div {...prop} />; class Component extends React.Component {
render() {
return <div {...this.props.prop} />;
}
} These ones, however, do generate warnings about missing propTypes validation: const Component = ({ prop }) => <div prop={prop} />; class Component extends React.Component {
render() {
return <div prop={this.props.prop} />;
}
} Might be related to destructuring and/or spreading? |
Interesting. I can't reproduce neither of the above examples with spreads (posted in #1958 (comment) by @asbjornh) in a test case. |
@bbthorntz are you on the latest version? I think this should work in 7.11.1. (#1958 (comment)) |
@alexzherdev yeah, version 7.11.1. |
@bbthorntz I specifically worked on spread props not disabling validation of other props that are used individually. If yours is a reduced example, would you be able to post the original code? Or are you able to actually make that reduced version fail? |
The key seems to be actually using |
I'm able to reproduce example from #1958 (comment) (and the ones from my previous comment #1958 (comment)) with the following config:
From
If I remove the spready bits from @swrobel's component I get the expected missing propTypes message. |
Ah, sorry for the confusion. All these issues were fixed in #1939, but that PR landed after 7.11.1. So you should expect them to get fixed in the next release. |
Thanks @alexzherdev! Looking forward to the fix. |
Very excited for this fix, impatiently waiting for |
I dropped back to 7.10.0 and that works correctly |
any plans to do a release soon @ljharb ? It's been a while and it would be great to not hard code the version anymore. |
got it. sorry to bother. just saw it had been a long time. Thanks for all of the work you put in. |
v7.12.1 is released; closing. Please file a new issue if there's still problems :-) |
Thanks for the follow-up @ljharb! |
This rule is not working in the latest version (7.11.1).
Missing propTypes for functions are not marked anymore. This was working fine on 7.10.0
The text was updated successfully, but these errors were encountered: