Skip to content

Commit d331af6

Browse files
committed
Add empty params check for unused prop types rule to fix empty proptype functions from causing crashes
1 parent f6e4c89 commit d331af6

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,9 @@ module.exports = {
652652
case 'ArrowFunctionExpression':
653653
case 'FunctionDeclaration':
654654
case 'FunctionExpression':
655+
if (node.params.length === 0) {
656+
break;
657+
}
655658
type = 'destructuring';
656659
properties = node.params[0].properties;
657660
if (inSetStateUpdater()) {

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,17 @@ ruleTester.run('no-unused-prop-types', rule, {
24402440
}
24412441
`,
24422442
parser: 'babel-eslint'
2443+
},
2444+
{
2445+
code: `
2446+
class MyComponent extends React.Component<Props> {
2447+
render() {
2448+
return <div>{ this.props.other }</div>
2449+
}
2450+
}
2451+
MyComponent.propTypes = { other: () => {} };
2452+
`,
2453+
parser: 'babel-eslint'
24432454
}
24442455
],
24452456

0 commit comments

Comments
 (0)