Skip to content

Add empty params check for unused prop types rule to fix empty proptype functions from causing crashes #1600

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Dec 20, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
11 changes: 11 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,17 @@ ruleTester.run('no-unused-prop-types', rule, {
}
`,
parser: 'babel-eslint'
},
{
code: `
class MyComponent extends React.Component<Props> {
render() {
return <div>{ this.props.other }</div>
}
}
MyComponent.propTypes = { other: () => {} };
`,
parser: 'babel-eslint'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this shouldn't need babel-eslint; can you either add a duplicate test case (one using the default parser, and one using babel-eslint), or, remove the parser line and only test using the default parser?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, I'll take out the parser line and leave the test cases using the default parser

}
],

Expand Down