🐛 useHookAtTopLevel
doesn't flag hook usages after an early return
#696
Labels
A-Linter
Area: linter
L-JavaScript
Language: JavaScript and super languages
S-Bug-confirmed
Status: report has been confirmed as a valid bug
Environment information
What happened?
When a React component contains an early return, calls to hooks after that point are not correctly identified as being conditional.
For instance, see the following playground example: https://www.biomejs.dev/playground?lintRules=all&code=aQBtAHAAbwByAHQAIAB7ACAAdQBzAGUAUwB0AGEAdABlACAAfQAgAGYAcgBvAG0AIAAiAHIAZQBhAGMAdAAiADsACgAKAGYAdQBuAGMAdABpAG8AbgAgAE0AeQBDAG8AbQBwAG8AbgBlAG4AdAAoAHsAIABiAGEAcgAgAH0AKQAgAHsACgAgACAAaQBmACAAKAAhAGIAYQByACkAIAB7AAoAIAAgACAAIAByAGUAdAB1AHIAbgAgAG4AdQBsAGwAOwAKACAAIAB9AAoACgAgACAAYwBvAG4AcwB0ACAAWwBmAG8AbwAsACAAcwBlAHQARgBvAG8AXQAgAD0AIAB1AHMAZQBTAHQAYQB0AGUAKAAxACkAOwAKAAoAIAAgAHIAZQB0AHUAcgBuACAAPABkAGkAdgA%2BAHsAZgBvAG8AfQA8AC8AZABpAHYAPgA7AAoAfQA%3D
Expected result
The call to
useState()
should be flagged as conditional.As a sidenote, I think it would be better if the
useHookAtTopLevel
rule were namednoConditionalHookCalls
instead, since that's its real purpose. As this example shows, being at the top-level isn't a guarantee something is not conditional.Code of Conduct
The text was updated successfully, but these errors were encountered: