Description
React version: 16.14.0
eslint-plugin-react-hooks
version: 4.2.0
eslint
version: 7.24.0
@typescript-eslint/parser
version: 4.17.0
@babel/eslint-parser
version: 7.13.4
A false positive from rules-of-hooks
, specifically the "called conditionally" report, cropped up in a codebase I work on this week. It was a very strange scenario where modifying portions of arbitrary logical expressions/operators would change which hooks were reported, or make the lint start passing altogether (when nothing about the structure of hooks had changed).
I drilled into it and diagnosed it as an overflow in the lint rule's path counting logic. Please find an isolated reproduction and brief writeup in this repository: https://github.com/camhux/eslint-react-hook-false-positive
Steps To Reproduce
- Clone https://github.com/camhux/eslint-react-hook-false-positive.
- Run
yarn repro
.
Link to code example: https://github.com/camhux/eslint-react-hook-false-positive/blob/main/repro.tsx
The current behavior
The useEffect
hook on repro.tsx:7
is flagged by rules-of-hooks
as being called conditionally.
The expected behavior
No errors are raised by the rules-of-hooks
rule for repro.tsx
.