-
-
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
Destructuring allows me to bypass prop-types rule #104
Comments
Destructuring is handled since With the following configuration I have the expected behavior with eslint test.js var Hello = React.createClass({
render: function() {
let {firstname} = this.props;
return <div>Hello {firstname}</div>;
}
}); .eslintrc {
"env": {
"node": true,
"es6": true
},
"ecmaFeatures": {
"jsx": true
},
"plugins": [
"react"
],
"rules": {
"react/prop-types": 2
}
} $ eslint --reset test.js
test.js
3:9 error 'firstname' is missing in props validation react/prop-types
✖ 1 problem (1 error, 0 warnings) If you still have the problem, can you post your full source code and |
Destructuring listing works fine for case with let {firstname} = this.props; but rule can't handle case of destructuring let { props: { firstname } } = this |
You're right, this case is not handled right now, but this is not the case reported by @jamischarles |
This may be related, or a new issue, but I have this problem: eslint-plugin-react version: 2.6.2 eslint version: 0.24.0 In My code: And the propTypes: Section.propTypes = {
content: PropTypes.shape({
section: PropTypes.object.isRequired,
stores: PropTypes.object.isRequired
})
}; Results in the error If I define my propTypes like this I don't get an error, but this is not what my propTypes should look like. Section.propTypes = {
content: PropTypes.object,
stores: PropTypes.object,
section: PropTypes.object
}; Of course if I define my consts like this I also don't get the error: const stores = this.props.content.stores;
const section = this.props.content.section; |
As I see it's two different issues. |
Yep, it seems there is a lot of different prop-types issues here, I'll try to clean this up:
@jamischarles I will close this issue for now, feel free to re-open it if you have more information to share about the problem you encountered and how to reproduce it. |
Thx @yannickcr |
Do you talk about the If it's the case, no it is not needed since the issue was already resolved. |
Thanks for the quick reply, guys. Created issue #136 |
When I use this rule:
"react/prop-types": 2,
This code
yields this
which I expect.
When I use destructuring however:
There is no eslint error.
The text was updated successfully, but these errors were encountered: