Skip to content

Commit e009744

Browse files
committed
Fix multiple var and destructuring handling in props-types (fixes #159)
1 parent 9773cfc commit e009744

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

lib/rules/prop-types.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -352,12 +352,12 @@ module.exports = function(context) {
352352
// Do not mark computed props as used.
353353
type = name !== '__COMPUTED_PROP__' ? 'direct' : null;
354354
} else if (
355-
node.parent.parent.declarations &&
356-
node.parent.parent.declarations[0].id.properties &&
357-
getKeyValue(node.parent.parent.declarations[0].id.properties[0])
355+
node.parent.id &&
356+
node.parent.id.properties &&
357+
getKeyValue(node.parent.id.properties[0])
358358
) {
359359
type = 'destructuring';
360-
properties = node.parent.parent.declarations[0].id.properties;
360+
properties = node.parent.id.properties;
361361
}
362362
break;
363363
case 'VariableDeclarator':

tests/lib/rules/prop-types.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,20 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
214214
destructuring: true,
215215
jsx: true
216216
}
217+
}, {
218+
code: [
219+
'class Hello extends React.Component {',
220+
' render() {',
221+
' var {firstname, lastname} = this.state, something = this.props;',
222+
' return <div>Hello {firstname}</div>;',
223+
' }',
224+
'}'
225+
].join('\n'),
226+
ecmaFeatures: {
227+
classes: true,
228+
destructuring: true,
229+
jsx: true
230+
}
217231
}, {
218232
code: [
219233
'class Hello extends React.Component {',

0 commit comments

Comments
 (0)