Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -1164,6 +1164,30 @@ const allTests = {
`,
errors: [loopError('useHookInsideLoop')],
},
{
code: normalizeIndent`
// Invalid because it's dangerous and might not warn otherwise.
// This *must* be invalid.
function ComponentWithHookInLoopCondition() {
while (useHookInsideLoop()) {
foo();
}
}
`,
errors: [loopError('useHookInsideLoop')],
},
{
code: normalizeIndent`
// Invalid because it's dangerous and might not warn otherwise.
// This *must* be invalid.
function ComponentWithHookInForCondition() {
for (; useHookInsideLoop(); ) {
foo();
}
}
`,
errors: [loopError('useHookInsideLoop')],
},
{
code: normalizeIndent`
// Invalid because it's dangerous and might not warn otherwise.
Expand Down
4 changes: 2 additions & 2 deletions packages/eslint-plugin-react-hooks/src/rules/RulesOfHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ const rule = {
if (pathList.has(segment.id)) {
const pathArray = [...pathList];
const cyclicSegments = pathArray.slice(
pathArray.indexOf(segment.id) + 1,
pathArray.indexOf(segment.id),
);
for (const cyclicSegment of cyclicSegments) {
cyclic.add(cyclicSegment);
Expand Down Expand Up @@ -422,7 +422,7 @@ const rule = {
if (pathList.has(segment.id)) {
const pathArray = Array.from(pathList);
const cyclicSegments = pathArray.slice(
pathArray.indexOf(segment.id) + 1,
pathArray.indexOf(segment.id),
);
for (const cyclicSegment of cyclicSegments) {
cyclic.add(cyclicSegment);
Expand Down