Skip to content
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

[fix] prefer-stateless-function: avoid crash on ts empty constructor #2582

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions lib/rules/prefer-stateless-function.js
Expand Up @@ -186,6 +186,7 @@ module.exports = {
const contextTypes = name === 'contextTypes';
const defaultProps = name === 'defaultProps';
const isUselessConstructor = property.kind === 'constructor' &&
!!property.value.body &&
isRedundantSuperCall(property.value.body.body, property.value.params);
const isRender = name === 'render';
return !isDisplayName && !isPropTypes && !contextTypes && !defaultProps && !isUselessConstructor && !isRender;
Expand Down
12 changes: 12 additions & 0 deletions tests/lib/rules/prefer-stateless-function.js
Expand Up @@ -157,6 +157,18 @@ ruleTester.run('prefer-stateless-function', rule, {
}
}
`
}, {
// Issue 2187
code: `
class Foo extends React.Component {
constructor(props)

render() {
return <div>{this.props.foo}</div>;
}
}
`,
parser: parsers.TYPESCRIPT_ESLINT
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is valid test case, similar to the two cases above in line 138 - 156.

}, {
// Use this.bar
code: `
Expand Down