Skip to content

Commit 20dff22

Browse files
author
Tamas Sule
committed
Adds more checks to MethodDefinition case and adds new test case for default parser
1 parent f9cc10d commit 20dff22

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
lines changed

lib/rules/prop-types.js

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,9 +607,14 @@ module.exports = {
607607
properties = node.params[0].properties;
608608
break;
609609
case 'MethodDefinition':
610-
type = 'destructuring';
611-
properties = node.value.params[0].properties;
612-
break;
610+
const destructuring = node.value && node.value.params && node.value.params[0] && node.value.params[0].type === 'ObjectPattern';
611+
if (destructuring) {
612+
type = 'destructuring';
613+
properties = node.value.params[0].properties;
614+
break;
615+
} else {
616+
return;
617+
}
613618
case 'VariableDeclarator':
614619
for (let i = 0, j = node.id.properties.length; i < j; i++) {
615620
// let {props: {firstname}} = this

tests/lib/rules/prop-types.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3115,6 +3115,25 @@ ruleTester.run('prop-types', rule, {
31153115
errors: [
31163116
{message: '\'foo\' is missing in props validation'}
31173117
]
3118+
}, {
3119+
code: [
3120+
'class Hello extends Component {',
3121+
' componentWillReceiveProps({foo}) {',
3122+
' if (foo) {',
3123+
' return;',
3124+
' }',
3125+
' }',
3126+
' render() {',
3127+
' return <div bar={this.props.bar} />;',
3128+
' }',
3129+
'}',
3130+
'Hello.propTypes = {',
3131+
' bar: PropTypes.func',
3132+
' }'
3133+
].join('\n'),
3134+
errors: [
3135+
{message: '\'foo\' is missing in props validation'}
3136+
]
31183137
}, {
31193138
code: [
31203139
'class Hello extends React.Component {',

0 commit comments

Comments
 (0)