Skip to content

Commit dd2d202

Browse files
committed
Handle no-init let-declared dependency identifier
Closes steadicat#4
1 parent 49b926c commit dd2d202

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

__tests__/require-usememo.ts

+8
Original file line numberDiff line numberDiff line change
@@ -142,5 +142,13 @@ ruleTester.run("useMemo", rule, {
142142
options: [{ strict: true }],
143143
errors: [{ messageId: "unknown-usememo-props" }],
144144
},
145+
{
146+
code: `const Component = () => {
147+
let myObject;
148+
myObject = {};
149+
return <Child prop={myObject} />;
150+
}`,
151+
errors: [{ messageId: "usememo-const" }],
152+
},
145153
],
146154
});

common.ts

+4
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,10 @@ function getIdentifierMemoStatus(
5353
if (node.type !== "VariableDeclarator") return MemoStatus.Memoized;
5454
if (node.parent.kind === "let") {
5555
context.report({ node, messageId: "usememo-const" });
56+
if (!node.init) {
57+
// Rely on usememo-const reported error to fail this identifier
58+
return MemoStatus.Memoized;
59+
}
5660
}
5761
return getExpressionMemoStatus(context, node.init);
5862
}

0 commit comments

Comments
 (0)