Skip to content

Commit e341dfa

Browse files
committed
Fix prop-types crash when destructuring props with spread only
1 parent cd5ef2b commit e341dfa

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

lib/rules/prop-types.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -540,6 +540,7 @@ module.exports = Components.detect(function(context, components, utils) {
540540
for (var i = 0, j = node.id.properties.length; i < j; i++) {
541541
// let {props: {firstname}} = this
542542
var thisDestructuring = (
543+
!hasSpreadOperator(node.id.properties[i]) &&
543544
(node.id.properties[i].key.name === 'props' || node.id.properties[i].key.value === 'props') &&
544545
node.id.properties[i].value.type === 'ObjectPattern'
545546
);

tests/lib/rules/prop-types.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1223,6 +1223,15 @@ ruleTester.run('prop-types', rule, {
12231223
'class Something extends Component {}'
12241224
].join('\n'),
12251225
parser: 'babel-eslint'
1226+
}, {
1227+
// Should not find any used props
1228+
code: [
1229+
'function Hello(props) {',
1230+
' const {...rest} = props;',
1231+
' return <div>Hello</div>;',
1232+
'}'
1233+
].join('\n'),
1234+
parserOptions: parserOptions
12261235
}
12271236
],
12281237

0 commit comments

Comments
 (0)