Skip to content

Commit 44a8ad2

Browse files
committed
refactor: minor improvements
1 parent 32d3d4e commit 44a8ad2

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-direct-set-state-in-use-effect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,9 @@ export default createRule<[], MessageID>({
8989
const [index] = n.arguments;
9090
if (!isAt || !index) return O.none();
9191
const initialScope = context.sourceCode.getScope(n);
92+
// const data = useState();
93+
// const index = 1;
94+
// data[index]();
9295
const value = getStaticValue(index, initialScope);
9396
if (value?.value === 1) return O.fromNullable(n.callee.object);
9497
return O.none();
@@ -123,7 +126,7 @@ export default createRule<[], MessageID>({
123126
const effectFunctionRef = MutRef.make<TSESTreeFunction | null>(null);
124127
const cleanUpFunctionRef = MutRef.make<TSESTreeFunction | null>(null);
125128
const indirectFunctionCalls = MutRef.make(Chunk.empty<TSESTree.CallExpression>());
126-
const indirectSetStateCalls = new Map<TSESTreeFunction, Chunk.Chunk<TSESTree.CallExpression>>();
129+
const indirectSetStateCalls = new WeakMap<TSESTreeFunction, Chunk.Chunk<TSESTree.CallExpression>>();
127130
// const onEffectFunctionEnter = (_: TSESTreeFunction) => {};
128131
// const onEffectFunctionExit = (_: TSESTreeFunction) => {};
129132
return {

packages/plugins/eslint-plugin-react-hooks-extra/src/rules/no-direct-set-state-in-use-layout-effect.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ export default createRule<[], MessageID>({
9090
}, n.callee);
9191
const [index] = n.arguments;
9292
if (!isAt || !index) return O.none();
93+
// const data = useState();
94+
// const index = 1;
95+
// data[index]();
9396
const initialScope = context.sourceCode.getScope(n);
9497
const value = getStaticValue(index, initialScope);
9598
if (value?.value === 1) return O.fromNullable(n.callee.object);
@@ -125,7 +128,7 @@ export default createRule<[], MessageID>({
125128
const effectFunctionRef = MutRef.make<TSESTreeFunction | null>(null);
126129
const cleanUpFunctionRef = MutRef.make<TSESTreeFunction | null>(null);
127130
const indirectFunctionCalls = MutRef.make(Chunk.empty<TSESTree.CallExpression>());
128-
const indirectSetStateCalls = new Map<TSESTreeFunction, Chunk.Chunk<TSESTree.CallExpression>>();
131+
const indirectSetStateCalls = new WeakMap<TSESTreeFunction, Chunk.Chunk<TSESTree.CallExpression>>();
129132
// const onEffectFunctionEnter = (_: TSESTreeFunction) => {};
130133
// const onEffectFunctionExit = (_: TSESTreeFunction) => {};
131134
return {

0 commit comments

Comments
 (0)