Skip to content

Commit dc7767b

Browse files
author
Yannick Croissant
committed
Fix no-unused-prop-types crash with destructured prop-types (fixes #938)
1 parent 0220022 commit dc7767b

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

lib/rules/no-unused-prop-types.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -579,8 +579,10 @@ module.exports = {
579579
for (var i = 0, j = node.id.properties.length; i < j; i++) {
580580
// let {props: {firstname}} = this
581581
var thisDestructuring = (
582-
(node.id.properties[i].key.name === 'props' || node.id.properties[i].key.value === 'props') &&
583-
node.id.properties[i].value.type === 'ObjectPattern'
582+
node.id.properties[i].key && (
583+
(node.id.properties[i].key.name === 'props' || node.id.properties[i].key.value === 'props') &&
584+
node.id.properties[i].value.type === 'ObjectPattern'
585+
)
584586
);
585587
// let {firstname} = props
586588
var genericDestructuring = isPropAttributeName(node) && (

tests/lib/rules/no-unused-prop-types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1413,6 +1413,15 @@ ruleTester.run('no-unused-prop-types', rule, {
14131413
'});'
14141414
].join('\n'),
14151415
parserOptions: parserOptions
1416+
}, {
1417+
// Destructured props in a stateless function
1418+
code: [
1419+
'const Hello = (props) => {',
1420+
' const {...rest} = props;',
1421+
' return <div />;',
1422+
'};'
1423+
].join('\n'),
1424+
parserOptions: parserOptions
14161425
}
14171426
],
14181427

0 commit comments

Comments
 (0)