-
-
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
add forbid-prop-types rule that by default forbids "any", "array", and "object" #225
Conversation
Looks great! Can you add some documentation ? Also, does it handle nested propTypes ? class Foo extends React.Component {
render: function () {
return <div>{this.props.bar.baz.something}</div>
}
}
Foo.propTypes = {
bar: React.PropTypes.shape({ // ok
baz: React.PropTypes.object.isRequired // not ok, PropTypes.object is forbidden
})
}; |
@yannickcr just added a test that verifies support for nested props. I'll get started on some documentation now. I'll flatten these commits once the docs are looking good. |
documentation added! |
👍 If it is good for you, can you squash your commits ? Then I will merge the PR. |
updated the docs to mention the suggested replacements for the default forbidden prop types, then squashed. should be good to merge once checks pass. |
Add forbid-prop-types rule (fixes #215)
Merged, thanks ! |
this class Foo extends React.Component {
const bar = this.props.bar;
render: function () {
return <div>{bar.baz.something}</div>
}
}
Foo.propTypes = {
bar: React.PropTypes.shape({ // ok
baz: React.PropTypes.object.isRequired // not ok, PropTypes.object is forbidden
})
}; |
That's correct behavior - you should use a shape, or objectOf, on |
@ljharb sorry for not make my self clear class Foo extends React.Component {
const bar = this.props.bar;
render: function () {
return <div>{bar.baz}</div>
}
}
Foo.propTypes = {
bar: React.PropTypes.shape({
baz: React.PropTypes.string // not ok, Prop defined but not used
})
}; this is ok: class Foo extends React.Component {
render: function () {
return <div>{this.props.bar.baz}</div>
}
}
Foo.propTypes = {
bar: React.PropTypes.shape({
baz: React.PropTypes.string // ok
})
}; |
Gotcha, can you file a new issue for that? |
yes, i opend #847 |
No description provided.