Skip to content

Commit a869bd1

Browse files
committed
Fix simple destructuring handling (fixes #137)
1 parent 824ba8d commit a869bd1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

lib/rules/prop-types.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -385,15 +385,14 @@ module.exports = function(context) {
385385
}
386386
break;
387387
case 'VariableDeclarator':
388-
type = 'destructuring';
389-
390388
for (var i = 0, j = node.id.properties.length; i < j; i++) {
391389
if (
392390
(node.id.properties[i].key.name !== 'props' && node.id.properties[i].key.value !== 'props') ||
393391
node.id.properties[i].value.type !== 'ObjectPattern'
394392
) {
395393
continue;
396394
}
395+
type = 'destructuring';
397396
properties = node.id.properties[i].value.properties;
398397
break;
399398
}

tests/lib/rules/prop-types.js

+10
Original file line numberDiff line numberDiff line change
@@ -538,6 +538,16 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
538538
'};'
539539
].join('\n'),
540540
parser: 'babel-eslint'
541+
}, {
542+
code: [
543+
'class Hello extends React.Component {',
544+
' render() {',
545+
' let {firstname} = this;',
546+
' return <div>{firstname}</div>;',
547+
' }',
548+
'};'
549+
].join('\n'),
550+
parser: 'babel-eslint'
541551
}
542552
],
543553

0 commit comments

Comments
 (0)