-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Additional cases for prop-types and no-unused-prop-types #1939
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
Conversation
if (containsObjectTypeSpread) { | ||
return {}; | ||
} | ||
// Mark if this shape has spread. We will know to consider all props from this shape as having propTypes, |
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.
Similar to the case with propTypes, if the shape contains a spread plus some properties e.g.
type Props = {
person: {
...$Exact<BasePerson>,
lastname: string
}
};
it would be unwise to throw away the information we have about lastname
just because we have a spread. By setting an additional flag and leaving the children data in place, we can detect if lastname
is being used.
@@ -1801,34 +1801,6 @@ ruleTester.run('no-unused-prop-types', rule, { | |||
' bar: PropTypes.bool', | |||
'};' | |||
].join('\n') | |||
}, { |
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.
So these tests are now able to detect that lastname
is not used. I understand this is a breaking change? Not insisting on any of these to go in, but seems like a good change to me.
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 we could consider it a bug that the rule missed it previously.
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 these new test cases also be added that don't use flow?
Sure. Wanted to start with a smaller set to validate the idea. |
Travis is flakey. |
Indeed; don't worry about those errors, I habitually rerun them when i see them. |
It’d be great if this could get merged before I push the used prop type refactoring, as they’re slightly interrelated. |
So I was adding test cases to both rules to bring them to parity after the refactoring, but a couple of things didn't make sense.
In particular, having just one flag for ignoring props validation doesn't seem to be enough (and that was the case before the refactoring as well). For instance, let's say we encounter a spread in props e.g.
That means any
this.props.foo
usage is considered to have a corresponding propType and it's ignored inprop-types
viaignorePropsValidation
flag we set in the helper.However, this shouldn't preclude us from being able to detect whether
lastname
is an unused propType inno-unused-prop-types
(this would be ignored if we met a{...props}
spread). But we can't rely on the same flag, because that flag means a different thing. So I'm proposing to split it into two.Also see comments inline.
Resolves #836