Skip to content

Commit 5959b5f

Browse files
golopotljharb
authored andcommitted
[fix] prefer-stateless-function: avoid crash on ts empty constructor
Fixes #2187
1 parent e231f44 commit 5959b5f

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

lib/rules/prefer-stateless-function.js

+1
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ module.exports = {
186186
const contextTypes = name === 'contextTypes';
187187
const defaultProps = name === 'defaultProps';
188188
const isUselessConstructor = property.kind === 'constructor' &&
189+
!!property.value.body &&
189190
isRedundantSuperCall(property.value.body.body, property.value.params);
190191
const isRender = name === 'render';
191192
return !isDisplayName && !isPropTypes && !contextTypes && !defaultProps && !isUselessConstructor && !isRender;

tests/lib/rules/prefer-stateless-function.js

+12
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,18 @@ ruleTester.run('prefer-stateless-function', rule, {
157157
}
158158
}
159159
`
160+
}, {
161+
// Issue 2187
162+
code: `
163+
class Foo extends React.Component {
164+
constructor(props)
165+
166+
render() {
167+
return <div>{this.props.foo}</div>;
168+
}
169+
}
170+
`,
171+
parser: parsers.TYPESCRIPT_ESLINT
160172
}, {
161173
// Use this.bar
162174
code: `

0 commit comments

Comments
 (0)