Skip to content

Commit

Permalink
Adds more checks to MethodDefinition case and adds new test case for …
Browse files Browse the repository at this point in the history
…default parser
  • Loading branch information
Tamas Sule committed Jan 21, 2018
1 parent f9cc10d commit 20dff22
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
11 changes: 8 additions & 3 deletions lib/rules/prop-types.js
Expand Up @@ -607,9 +607,14 @@ module.exports = {
properties = node.params[0].properties;
break;
case 'MethodDefinition':
type = 'destructuring';
properties = node.value.params[0].properties;
break;
const destructuring = node.value && node.value.params && node.value.params[0] && node.value.params[0].type === 'ObjectPattern';
if (destructuring) {
type = 'destructuring';
properties = node.value.params[0].properties;
break;
} else {
return;
}
case 'VariableDeclarator':
for (let i = 0, j = node.id.properties.length; i < j; i++) {
// let {props: {firstname}} = this
Expand Down
19 changes: 19 additions & 0 deletions tests/lib/rules/prop-types.js
Expand Up @@ -3115,6 +3115,25 @@ ruleTester.run('prop-types', rule, {
errors: [
{message: '\'foo\' is missing in props validation'}
]
}, {
code: [
'class Hello extends Component {',
' componentWillReceiveProps({foo}) {',
' if (foo) {',
' return;',
' }',
' }',
' render() {',
' return <div bar={this.props.bar} />;',
' }',
'}',
'Hello.propTypes = {',
' bar: PropTypes.func',
' }'
].join('\n'),
errors: [
{message: '\'foo\' is missing in props validation'}
]
}, {
code: [
'class Hello extends React.Component {',
Expand Down

0 comments on commit 20dff22

Please sign in to comment.