From a869bd1ebb7a944be83109f109c6636a281e8eb2 Mon Sep 17 00:00:00 2001 From: Yannick Croissant Date: Wed, 1 Jul 2015 22:40:41 +0000 Subject: [PATCH] Fix simple destructuring handling (fixes #137) --- lib/rules/prop-types.js | 3 +-- tests/lib/rules/prop-types.js | 10 ++++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/lib/rules/prop-types.js b/lib/rules/prop-types.js index 658f50fae4..650f4752f1 100644 --- a/lib/rules/prop-types.js +++ b/lib/rules/prop-types.js @@ -385,8 +385,6 @@ module.exports = function(context) { } break; case 'VariableDeclarator': - type = 'destructuring'; - for (var i = 0, j = node.id.properties.length; i < j; i++) { if ( (node.id.properties[i].key.name !== 'props' && node.id.properties[i].key.value !== 'props') || @@ -394,6 +392,7 @@ module.exports = function(context) { ) { continue; } + type = 'destructuring'; properties = node.id.properties[i].value.properties; break; } diff --git a/tests/lib/rules/prop-types.js b/tests/lib/rules/prop-types.js index bdf907359d..0da4cc3821 100644 --- a/tests/lib/rules/prop-types.js +++ b/tests/lib/rules/prop-types.js @@ -538,6 +538,16 @@ eslintTester.addRuleTest('lib/rules/prop-types', { '};' ].join('\n'), parser: 'babel-eslint' + }, { + code: [ + 'class Hello extends React.Component {', + ' render() {', + ' let {firstname} = this;', + ' return
{firstname}
;', + ' }', + '};' + ].join('\n'), + parser: 'babel-eslint' } ],