Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

💅 useHookAtTopLevel: false positives in nested functions #1473

Closed
1 task done
nstepien opened this issue Jan 8, 2024 · 1 comment · Fixed by #1517
Closed
1 task done

💅 useHookAtTopLevel: false positives in nested functions #1473

nstepien opened this issue Jan 8, 2024 · 1 comment · Fixed by #1517
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@nstepien
Copy link
Contributor

nstepien commented Jan 8, 2024

Environment information

playground

Rule name

useHookAtTopLevel

Playground link

https://biomejs.dev/playground/?indentStyle=space&quoteStyle=single&trailingComma=none&lintRules=all&code=aQBtAHAAbwByAHQAIAB7ACAAdABlAHMAdAAsACAAZQB4AHAAZQBjAHQAIAB9ACAAZgByAG8AbQAgACcAdgBpAHQAZQBzAHQAJwA7AAoAaQBtAHAAbwByAHQAIAB7ACAAdQBzAGUAUwB0AGEAdABlACAAfQAgAGYAcgBvAG0AIAAnAHIAZQBhAGMAdAAnADsACgBpAG0AcABvAHIAdAAgAHsAIAByAGUAbgBkAGUAcgAsACAAcgBlAG4AZABlAHIASABvAG8AawAgAH0AIABmAHIAbwBtACAAJwBAAHQAZQBzAHQAaQBuAGcALQBsAGkAYgByAGEAcgB5AC8AcgBlAGEAYwB0ACcAOwAKAGkAbQBwAG8AcgB0ACAAewAgAHUAcwBlAEgAbwBvAGsAIAB9ACAAZgByAG8AbQAgACcALgAvAHUAcwBlAEgAbwBvAGsAJwA7AAoACgB0AGUAcwB0ACgAJwBhACcALAAgACgAKQAgAD0APgAgAHsACgAgACAAZgB1AG4AYwB0AGkAbwBuACAAVABlAHMAdABDAG8AbQBwAG8AbgBlAG4AdAAoACkAIAB7AAoAIAAgACAAIAB1AHMAZQBTAHQAYQB0AGUAKAApADsACgAgACAAIAAgAHUAcwBlAEgAbwBvAGsAKAApADsACgAgACAAfQAKAAoAIAAgAHIAZQBuAGQAZQByACgAPABUAGUAcwB0AEMAbwBtAHAAbwBuAGUAbgB0ACAALwA%2BACkAOwAKAH0AKQA7AAoACgB0AGUAcwB0ACgAJwBiACcALAAgACgAKQAgAD0APgAgAHsACgAgACAAYwBvAG4AcwB0ACAAewAgAHIAZQBzAHUAbAB0ACAAfQAgAD0AIAByAGUAbgBkAGUAcgBIAG8AbwBrACgAKAApACAAPQA%2BACAAdQBzAGUASABvAG8AawAoACkAKQA7AAoACgAgACAAZQB4AHAAZQBjAHQAKAByAGUAcwB1AGwAdAAuAGMAdQByAHIAZQBuAHQAKQAuAHQAbwBCAGUARABlAGYAaQBuAGUAZAAoACkAOwAKAH0AKQA7AAoA

Expected result

We have some hook usage in tests like in the playground link above. These are valid and are called unconditionally.
The eslint equivalent does not flag these as invalid.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@arendjr
Copy link
Contributor

arendjr commented Jan 8, 2024

Hah, this one is on me, yes. The behavior was intentional, because you shouldn’t call hooks from nested functions, but that assumes the component/hook it is defined in as at the top-level of the file.

I guess I just need to check for hook calls in nested functions whether the enclosing function is a hook or component (based on naming conventions). Feel free to assign me!

@ematipico ematipico added A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug labels Jan 9, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants