Skip to content

Commit

Permalink
[fix] prefer-stateless-function: avoid crash on ts empty constructor
Browse files Browse the repository at this point in the history
Fixes #2187
  • Loading branch information
golopot authored and ljharb committed Mar 1, 2020
1 parent e231f44 commit 5959b5f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions lib/rules/prefer-stateless-function.js
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
}, {
// Use this.bar
code: `
Expand Down

0 comments on commit 5959b5f

Please sign in to comment.