Skip to content

Commit

Permalink
Merge pull request #1600 from kevinzwhuang/fix-unused-prop-types
Browse files Browse the repository at this point in the history
Add empty params check for unused prop types rule to fix empty proptype functions from causing crashes
  • Loading branch information
ljharb authored Dec 20, 2017
2 parents a908eb3 + 6015af2 commit 9b8ea5e
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,9 @@ module.exports = {
case 'ArrowFunctionExpression':
case 'FunctionDeclaration':
case 'FunctionExpression':
if (node.params.length === 0) {
break;
}
type = 'destructuring';
properties = node.params[0].properties;
if (inSetStateUpdater()) {
Expand Down
40 changes: 40 additions & 0 deletions tests/lib/rules/no-unused-prop-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -2440,6 +2440,46 @@ ruleTester.run('no-unused-prop-types', rule, {
}
`,
parser: 'babel-eslint'
},
{
code: `
class MyComponent extends React.Component {
render() {
return <div>{ this.props.other }</div>
}
}
MyComponent.propTypes = { other: () => {} };
`
},
{
code: `
class MyComponent extends React.Component {
render() {
return <div>{ this.props.other }</div>
}
}
MyComponent.propTypes = { other() {} };
`
},
{
code: `
class MyComponent extends React.Component {
render() {
return <div>{ this.props.other }</div>
}
}
MyComponent.propTypes = { other: function () {} };
`
},
{
code: `
class MyComponent extends React.Component {
render() {
return <div>{ this.props.other }</div>
}
}
MyComponent.propTypes = { * other() {} };
`
}
],

Expand Down

0 comments on commit 9b8ea5e

Please sign in to comment.