Skip to content

Commit

Permalink
[Fix] no-arrow-function-lifecycle: prevent crashing on ClassProperty
Browse files Browse the repository at this point in the history
Fixes #3093
  • Loading branch information
AriPerkkio authored Oct 5, 2021
1 parent 210865e commit 197c7a4
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/rules/no-arrow-function-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,10 @@ module.exports = {
*/
function reportNoArrowFunctionLifecycle(properties) {
properties.forEach((node) => {
if (!node || !node.value) {
return;
}

const propertyName = astUtil.getPropertyName(node);
const nodeType = node.value.type;
const isLifecycleMethod = (
Expand Down
13 changes: 12 additions & 1 deletion tests/lib/rules/no-arrow-function-lifecycle.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,18 @@ ruleTester.run('no-arrow-function-lifecycle', rule, {
});
`
}
],
].concat(
parsers.TS([
{
code: `
class MyComponent extends React.Component {
onChange: () => void;
}
`,
parser: parsers['@TYPESCRIPT_ESLINT']
}
])
),

invalid: [
{
Expand Down

0 comments on commit 197c7a4

Please sign in to comment.