Skip to content

Commit

Permalink
Fix nested props destructuring (fixes #136)
Browse files Browse the repository at this point in the history
  • Loading branch information
yannickcr committed Jun 29, 2015
1 parent 999e7c4 commit 94b439b
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -423,10 +423,19 @@ module.exports = function(context) {
continue;
}
var propName = getKeyValue(properties[k]);

var currentNode = node;
allNames = [];
while (currentNode.property && currentNode.property.name !== 'props') {
allNames.unshift(currentNode.property.name);
currentNode = currentNode.object;
}
allNames.push(propName);

if (propName) {
usedPropTypes.push({
name: propName,
allNames: [propName],
allNames: allNames,
node: properties[k]
});
}
Expand Down
16 changes: 16 additions & 0 deletions tests/lib/rules/prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,22 @@ eslintTester.addRuleTest('lib/rules/prop-types', {
].join('\n'),
parser: 'babel-eslint',
args: [1, {ignore: ['name']}]
}, {
code: [
'class Hello extends React.Component {',
' render() {',
' const {firstname, lastname} = this.props.name;',
' return <div>{firstname} {lastname}</div>;',
' }',
'}',
'Hello.propTypes = {',
' name: PropTypes.shape({',
' firstname: PropTypes.string,',
' lastname: PropTypes.string',
' })',
'};'
].join('\n'),
parser: 'babel-eslint'
}
],

Expand Down

0 comments on commit 94b439b

Please sign in to comment.