diff --git a/index.js b/index.js
index ca17399..198a3aa 100644
--- a/index.js
+++ b/index.js
@@ -36,6 +36,18 @@ function getReturnStatement(node) {
return;
}
+ if (node.type === 'ClassDeclaration') {
+ // For class-based components, find the render function, then its return statement
+ renderFunction = node.body?.body?.find(
+ (statement) =>
+ statement.type === 'MethodDefinition' &&
+ statement.key.name === 'render',
+ );
+ return renderFunction.value?.body?.body?.find(
+ (statement) => statement.type === 'ReturnStatement',
+ );
+ }
+
return node.type === 'VariableDeclaration'
? node.declarations?.[0]?.init?.body?.body?.find(
(statement) => statement.type === 'ReturnStatement',
@@ -99,7 +111,8 @@ const rules = {
.filter(
(child) =>
child.type === 'VariableDeclaration' ||
- child.type === 'FunctionDeclaration',
+ child.type === 'FunctionDeclaration' ||
+ child.type === 'ClassDeclaration',
)
.filter((child) => {
let flag = false;
diff --git a/test.js b/test.js
index 326119a..f4c64c9 100644
--- a/test.js
+++ b/test.js
@@ -9,6 +9,7 @@ const { join } = require('path');
const singleComponent = `const temp = () => {