Skip to content

Commit 9b8ea5e

Browse files
authored
Merge pull request #1600 from kevinzwhuang/fix-unused-prop-types
Add empty params check for unused prop types rule to fix empty proptype functions from causing crashes
2 parents a908eb3 + 6015af2 commit 9b8ea5e

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-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: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2440,6 +2440,46 @@ ruleTester.run('no-unused-prop-types', rule, {
24402440
}
24412441
`,
24422442
parser: 'babel-eslint'
2443+
},
2444+
{
2445+
code: `
2446+
class MyComponent extends React.Component {
2447+
render() {
2448+
return <div>{ this.props.other }</div>
2449+
}
2450+
}
2451+
MyComponent.propTypes = { other: () => {} };
2452+
`
2453+
},
2454+
{
2455+
code: `
2456+
class MyComponent extends React.Component {
2457+
render() {
2458+
return <div>{ this.props.other }</div>
2459+
}
2460+
}
2461+
MyComponent.propTypes = { other() {} };
2462+
`
2463+
},
2464+
{
2465+
code: `
2466+
class MyComponent extends React.Component {
2467+
render() {
2468+
return <div>{ this.props.other }</div>
2469+
}
2470+
}
2471+
MyComponent.propTypes = { other: function () {} };
2472+
`
2473+
},
2474+
{
2475+
code: `
2476+
class MyComponent extends React.Component {
2477+
render() {
2478+
return <div>{ this.props.other }</div>
2479+
}
2480+
}
2481+
MyComponent.propTypes = { * other() {} };
2482+
`
24432483
}
24442484
],
24452485

0 commit comments

Comments
 (0)