Skip to content

Commit 33a8918

Browse files
committed
rules-of-hooks: fix do/while
1 parent 6d7758a commit 33a8918

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

packages/eslint-plugin-react-hooks/src/RulesOfHooks.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ export default {
272272
if (pathList.has(segment.id)) {
273273
const pathArray = Array.from(pathList);
274274
const cyclicSegments = pathArray.slice(
275-
pathArray.indexOf(segment.id) + 1,
275+
pathArray.indexOf(segment.id) - 1,
276276
);
277277
for (const cyclicSegment of cyclicSegments) {
278278
cyclic.add(cyclicSegment);
@@ -300,7 +300,14 @@ export default {
300300
}
301301
}
302302

303-
cache.set(segment.id, paths);
303+
// If our segment is reachable then there should be at least one path
304+
// to it to the end of our code path.
305+
if (segment.reachable && paths === BigInt('0')) {
306+
cache.delete(segment.id);
307+
} else {
308+
cache.set(segment.id, paths);
309+
}
310+
304311
return paths;
305312
}
306313

0 commit comments

Comments
 (0)