{"action":"created","issue":{"url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/442","repository_url":"https://api.github.com/repos/yannickcr/eslint-plugin-react","labels_url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/442/labels{/name}","comments_url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/442/comments","events_url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/442/events","html_url":"https://github.com/yannickcr/eslint-plugin-react/issues/442","id":133484435,"number":442,"title":"Assignment of props to a variable allows bypass of prop-types rule","user":{"login":"timoxley","id":43438,"avatar_url":"https://avatars.githubusercontent.com/u/43438?v=3","gravatar_id":"","url":"https://api.github.com/users/timoxley","html_url":"https://github.com/timoxley","followers_url":"https://api.github.com/users/timoxley/followers","following_url":"https://api.github.com/users/timoxley/following{/other_user}","gists_url":"https://api.github.com/users/timoxley/gists{/gist_id}","starred_url":"https://api.github.com/users/timoxley/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/timoxley/subscriptions","organizations_url":"https://api.github.com/users/timoxley/orgs","repos_url":"https://api.github.com/users/timoxley/repos","events_url":"https://api.github.com/users/timoxley/events{/privacy}","received_events_url":"https://api.github.com/users/timoxley/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":0,"created_at":"2016-02-13T23:57:54Z","updated_at":"2016-02-14T17:19:56Z","closed_at":null,"body":"This case will not be detected by prop-types rule:\r\n```js\r\nvar props = this.props\r\nconsole.log(props.something)\r\n```\r\nNor this:\r\n```js\r\nvar {props} = this\r\nconsole.log(props.something)\r\n```\r\n\r\nI can understand why this may be difficult/impossible if props is being assigned multiple times or within a something dynamic like a conditional but perhaps it's possible to detect these two simple cases. \r\n\r\n~~According to #298, it appears that there might (?) be some support for `var props = this.props` but I couldn't get this working in my code.~~\r\n\r\nedit: According to the [prop-types tests](\r\nhttps://github.com/yannickcr/eslint-plugin-react/blob/e716f99f35579039be1c115d7648701ce90ceb56/tests/lib/rules/prop-types.js#L790-L801), it appears this is known to not work :disappointed::\r\n\r\n```js\r\n    }, {\r\n      // Reassigned props are ignored\r\n      code: [\r\n        'export class Hello extends Component {',\r\n        '  render() {',\r\n        '    const props = this.props;',\r\n        '    return <div>Hello {props.name.firstname} {props[\\'name\\'].lastname}</div>',\r\n        '  }',\r\n        '}'\r\n      ].join('\\n'),\r\n      parser: 'babel-eslint'\r\n    }, {\r\n```\r\n\r\n[Source](https://github.com/yannickcr/eslint-plugin-react/blob/e716f99f35579039be1c115d7648701ce90ceb56/tests/lib/rules/prop-types.js#L790-L801)\r\n\r\nSemi-Related Issues for reference:\r\n\r\nhttps://github.com/yannickcr/eslint-plugin-react/issues/27\r\nhttps://github.com/yannickcr/eslint-plugin-react/pull/36\r\nhttps://github.com/yannickcr/eslint-plugin-react/issues/104\r\nhttps://github.com/yannickcr/eslint-plugin-react/pull/112\r\nhttps://github.com/yannickcr/eslint-plugin-react/pull/124\r\nhttps://github.com/yannickcr/eslint-plugin-react/issues/136\r\nhttps://github.com/yannickcr/eslint-plugin-react/issues/298\r\n\r\nAside: Benefit of this pattern is that it removes risk of unexpected `this`, is more terse than `this.props.something` and keeps props nested under a 'props' namespace thus prop values cannot be confused/shadowed by other vars.\r\n\r\n----\r\n\r\nRepro case:\r\n\r\n#### index.js\r\n```js\r\nimport React from 'react'\r\n\r\nclass ShouldFail extends React.Component {\r\n  render () {\r\n    const props = this.props\r\n    console.log(props.something)\r\n  }\r\n}\r\n```\r\n\r\n#### package.json\r\n```js\r\n{\r\n  \"name\": \"eslint-react-prop-types-test\",\r\n  \"version\": \"1.0.0\",\r\n  \"main\": \"index.js\",\r\n  \"scripts\": {\r\n    \"test\": \"eslint index.js\"\r\n  },\r\n  \"dependencies\": {\r\n    \"babel-eslint\": \"^4.1.8\",\r\n    \"eslint\": \"^2.0.0\",\r\n    \"eslint-plugin-react\": \"^3.16.1\"\r\n  }\r\n}\r\n```\r\n\r\n#### .eslintrc\r\n```js\r\n{\r\n  \"parser\": \"babel-eslint\",\r\n  \"plugins\": [\r\n    \"react\"\r\n  ],\r\n  \"rules\": {\r\n    \"react/prop-types\": 2\r\n  }\r\n}\r\n\r\n```"},"comment":{"url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/comments/183932711","html_url":"https://github.com/yannickcr/eslint-plugin-react/issues/442#issuecomment-183932711","issue_url":"https://api.github.com/repos/yannickcr/eslint-plugin-react/issues/442","id":183932711,"user":{"login":"yannickcr","id":13209,"avatar_url":"https://avatars.githubusercontent.com/u/13209?v=3","gravatar_id":"","url":"https://api.github.com/users/yannickcr","html_url":"https://github.com/yannickcr","followers_url":"https://api.github.com/users/yannickcr/followers","following_url":"https://api.github.com/users/yannickcr/following{/other_user}","gists_url":"https://api.github.com/users/yannickcr/gists{/gist_id}","starred_url":"https://api.github.com/users/yannickcr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/yannickcr/subscriptions","organizations_url":"https://api.github.com/users/yannickcr/orgs","repos_url":"https://api.github.com/users/yannickcr/repos","events_url":"https://api.github.com/users/yannickcr/events{/privacy}","received_events_url":"https://api.github.com/users/yannickcr/received_events","type":"User","site_admin":false},"created_at":"2016-02-14T17:19:56Z","updated_at":"2016-02-14T17:19:56Z","body":"Yes, tracking variable reassignment can be very difficult so it is ignored for now.\r\n\r\nI don't know how popular are these patterns, if it's worth it we could try to add support for them.\r\n\r\nAlso I really don't know what amount of work would be required for that, it needs investigation."}}