-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
static analysis of propTypes #2088
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
Comments
The former case should be covering
|
I think the former case is fixed in master. I had a similar test case here https://github.com/yannickcr/eslint-plugin-react/pull/1939/files#diff-9dbe8e4f339ea9d6faa56b31c38e71bbR4871 |
Spreading propTypes was actually breaking static analysis for all props, but I might have been on an older version. I'll check later. For |
#1764 is the same issue. This happens anytime there is a reference to props. As regards to the other issue (spread in propTypes definition), this is breaking static analysis for all props for me. Using eslint-plugin-react v 7.11.1 and react v 15.5.4. |
v7.12.0 is released; is this still an issue? |
Yes. We use things like: class C extends React.Component {
static propTypes = {
...B.propTypes,
own: PropTypes.any
}
static defaultProps = {
foo: "bar" // defined in B.propTypes but reported as missing from C.propTypes
}
} |
That’s impossible to fix with a linter; I’d recommend spreading in both B.propTypes and B.defaultProps so there’s no confusion about where the source of truth is. |
@lagesag that looks like a different issue. @ljharb I am stilling having this issue after updating to 7.12.0. Again, the issue is that using spread in proptypes disables static analysis:
Is this the expected behavior because any prop could be in paddingPropTypes? |
@aw-davidson correct, this is the intended behavior. |
@ljharb what about a rule that warns against dynamically defining propTypes? |
Spreading shared propTypes into a component's propTypes is not an antipattern, it's a good pattern. At some point, linting can't catch everything, and you have to let your unit tests catch things :-) |
I've noticed some patterns that can interfere with eslint's static analysis of propTypes. For example:
Also, unpacking props from this will break static analysis:
const { props } = this;
These patterns interfere with eslint telling you a prop is missing in props validation. I would like to contribute my solution for this issue.
The text was updated successfully, but these errors were encountered: