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: unconditional hook usage flagged as conditionally called #610

Closed
1 task done
nstepien opened this issue Oct 26, 2023 · 11 comments · Fixed by #1393 or #1441
Closed
1 task done

🐛 useHookAtTopLevel: unconditional hook usage flagged as conditionally called #610

nstepien opened this issue Oct 26, 2023 · 11 comments · Fixed by #1393 or #1441
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug

Comments

@nstepien
Copy link
Sponsor Contributor

nstepien commented Oct 26, 2023

Environment information

https://biomejs.dev/playground/?indentStyle=space&quoteStyle=single&trailingComma=none&lintRules=all&code=aQBtAHAAbwByAHQAIAB7ACAAYwByAGUAYQB0AGUAQwBvAG4AdABlAHgAdAAsACAAdQBzAGUAQwBhAGwAbABiAGEAYwBrACwAIAB1AHMAZQBDAG8AbgB0AGUAeAB0ACAAfQAgAGYAcgBvAG0AIAAnAHIAZQBhAGMAdAAnADsACgAKAGMAbwBuAHMAdAAgAEMAbwBuAHQAZQB4AHQAIAA9ACAAYwByAGUAYQB0AGUAQwBvAG4AdABlAHgAdAAoAHsAfQApADsACgAKAGUAeABwAG8AcgB0ACAAZgB1AG4AYwB0AGkAbwBuACAAdQBzAGUASwBlAHkAKABrAGUAeQA6ACAAcwB0AHIAaQBuAGcAKQAgAHsACgAgACAAcgBlAHQAdQByAG4AIAB1AHMAZQBDAG8AbgB0AGUAeAB0ACgAQwBvAG4AdABlAHgAdAApAFsAawBlAHkAXQA7AAoAfQAKAAoAZQB4AHAAbwByAHQAIABmAHUAbgBjAHQAaQBvAG4AIAB1AHMAZQBTAHQAdQBmAGYAKAApACAAewAKACAAIAByAGUAdAB1AHIAbgAgAHsACgAgACAAIAAgAGEAYgBjADoAIAB1AHMAZQBDAGEAbABsAGIAYQBjAGsAKAAoACkAIAA9AD4AIABuAHUAbABsACwAIABbAF0AKQAKACAAIAB9ADsACgB9AAoACgBlAHgAcABvAHIAdAAgAGYAdQBuAGMAdABpAG8AbgAgAHUAcwBlAFMAdAB1AGYAZgAyACgAKQAgAHsACgAgACAAcgBlAHQAdQByAG4AIABbAHUAcwBlAEMAYQBsAGwAYgBhAGMAawAoACgAKQAgAD0APgAgAG4AdQBsAGwALAAgAFsAXQApAF0AOwAKAH0ACgA%3D

https://biomejs.dev/playground/?indentStyle=space&quoteStyle=single&trailingComma=none&lintRules=all&code=aQBtAHAAbwByAHQAIAB7ACAAYwByAGUAYQB0AGUAQwBvAG4AdABlAHgAdAAsACAAdQBzAGUAQwBhAGwAbABiAGEAYwBrACwAIAB1AHMAZQBDAG8AbgB0AGUAeAB0ACAAfQAgAGYAcgBvAG0AIAAnAHIAZQBhAGMAdAAnADsACgAKAGMAbwBuAHMAdAAgAEMAbwBuAHQAZQB4AHQAIAA9ACAAYwByAGUAYQB0AGUAQwBvAG4AdABlAHgAdAAoAHsAfQApADsACgAKAGUAeABwAG8AcgB0ACAAZgB1AG4AYwB0AGkAbwBuACAAdQBzAGUASwBlAHkAKABrAGUAeQA6ACAAcwB0AHIAaQBuAGcAKQAgAHsACgAgACAAcgBlAHQAdQByAG4AIAB1AHMAZQBDAG8AbgB0AGUAeAB0ACgAQwBvAG4AdABlAHgAdAApAFsAawBlAHkAXQA7AAoAfQAKAAoAZQB4AHAAbwByAHQAIABmAHUAbgBjAHQAaQBvAG4AIAB1AHMAZQBTAHQAdQBmAGYAKAApACAAewAKACAAIAByAGUAdAB1AHIAbgAgAHsACgAgACAAIAAgAGEAYgBjADoAIAB1AHMAZQBDAGEAbABsAGIAYQBjAGsAKAAoACkAIAA9AD4AIABuAHUAbABsACwAIABbAF0AKQAKACAAIAB9ADsACgB9AAoACgBlAHgAcABvAHIAdAAgAGYAdQBuAGMAdABpAG8AbgAgAHUAcwBlAFMAdAB1AGYAZgAyACgAKQAgAHsACgAgACAAcgBlAHQAdQByAG4AIABbAHUAcwBlAEMAYQBsAGwAYgBhAGMAawAoACgAKQAgAD0APgAgAG4AdQBsAGwALAAgAFsAXQApAF0AOwAKAH0ACgA%3D

What happened?

Biome flags these hooks as being conditionally called when they are not.

Expected result

No issues reported.

Code of Conduct

  • I agree to follow Biome's Code of Conduct
@unvalley unvalley added A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Oct 28, 2023
@nissy-dev nissy-dev added the S-Bug-confirmed Status: report has been confirmed as a valid bug label Oct 28, 2023
@msdlisper
Copy link
Contributor

https://stackblitz.com/edit/node-74lxwb?file=src%2Findex.js,package.json
Links replicated with ESLint:
execute npm run lint

@atheck
Copy link

atheck commented Nov 21, 2023

This also happens when using function components in objects:

const obj = {
  Component() {
    useState(0);

    return ...;
  }
}

@arendjr
Copy link
Contributor

arendjr commented Jan 1, 2024

I have included fixes for the edge cases in the playground in #1393.

The case reported in the comment above is not yet fixed since it's a little trickier to do so. Update: The snippet from above (implementing components inside an object literal) is now supported too.

@nstepien
Copy link
Sponsor Contributor Author

nstepien commented Jan 4, 2024

@ematipico looks like there's still a bug in the playground link

@ematipico
Copy link
Member

cc @arendjr

@ematipico ematipico reopened this Jan 4, 2024
@arendjr
Copy link
Contributor

arendjr commented Jan 4, 2024

Huh, I had not included that one in the test cases, because I didn’t see a failure before, so I figured it must’ve been fixed already. Oh well, this fix shouldn’t be too hard :)

@nstepien
Copy link
Sponsor Contributor Author

nstepien commented Jan 4, 2024

IIRC it was fixed before, there might be a regression somewhere 🤔

@nstepien
Copy link
Sponsor Contributor Author

nstepien commented Jan 7, 2024

I can still see a false-positive in the playground, is it not updated? 🤔

@arendjr
Copy link
Contributor

arendjr commented Jan 7, 2024

Hm, good question. I would suspect so, because if it’s still not fixed I’ll eat my shoe 😂

@Conaclos Conaclos reopened this Jan 7, 2024
@arendjr
Copy link
Contributor

arendjr commented Jan 7, 2024

Playground seems fine now? 🤔

@nstepien
Copy link
Sponsor Contributor Author

nstepien commented Jan 7, 2024

Nice! Re-closing then, thanks!

@nstepien nstepien closed this as completed Jan 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-Linter Area: linter L-JavaScript Language: JavaScript and super languages S-Bug-confirmed Status: report has been confirmed as a valid bug
Projects
None yet
8 participants