Skip to content

Commit c70163d

Browse files
AriPerkkioljharb
authored andcommitted
[Fix] no-arrow-function-lifecycle: prevent crashing on ClassProperty
Fixes #3093
1 parent f93f90a commit c70163d

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

lib/rules/no-arrow-function-lifecycle.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ module.exports = {
4444
*/
4545
function reportNoArrowFunctionLifecycle(properties) {
4646
properties.forEach((node) => {
47+
if (!node || !node.value) {
48+
return;
49+
}
50+
4751
const propertyName = astUtil.getPropertyName(node);
4852
const nodeType = node.value.type;
4953
const isLifecycleMethod = (

tests/lib/rules/no-arrow-function-lifecycle.js

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,18 @@ ruleTester.run('no-arrow-function-lifecycle', rule, {
348348
});
349349
`,
350350
},
351-
],
351+
].concat(
352+
parsers.TS([
353+
{
354+
code: `
355+
class MyComponent extends React.Component {
356+
onChange: () => void;
357+
}
358+
`,
359+
parser: parsers['@TYPESCRIPT_ESLINT'],
360+
},
361+
])
362+
),
352363

353364
invalid: [
354365
{

0 commit comments

Comments
 (0)