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
  • Loading branch information
golopot committed Mar 1, 2020
1 parent 434b45f commit 5299132
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
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
}, {
// Use this.bar
code: `
Expand Down

0 comments on commit 5299132

Please sign in to comment.