-
-
Notifications
You must be signed in to change notification settings - Fork 525
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
reports errors on code that is not React
#3476
Comments
Reproduced here. It is indeed an error. I'm not familiar with nestjs and don't know what use you are using useHookAtTopLevel for, but I would have thought it would be better not to check lint as this is a React rule in the first place. |
That link 404s. This rule should only be checked in |
Sorry, this was private repository.
Certainly, that sounds better. |
I think we could use a couple of heuristics like checking Could I take this task to try that out? |
Sure! I'll go ahead and assign you. |
Please be aware we already have such a heuristic:
I suppose this is not used by the rule yet… |
Yep, that's the function I wanted to use. I was thinking now that maybe limiting this to For example: https://github.com/ilyalesik/react-media-hook/blob/master/index.js Edited: Thinking about it a bit more, only checking if it's inside a react component is not correct either because it might be used inside another hook. I'll take that into consideration too. |
A similar case was fixed for some jest functions that start with “use”
I tried adding other heuristics, like checking that the root caller is a react component or a hook, but so far all I tried ends up changing the snapshots because some cases get uncovered. We might need to do some comprimises with this. |
It might be useful if biome could inspect |
@dyc3 I think your suggestion is actually a good workaround. I opened a Draft PR with this change. I need to find a way to run the snapshots simulating an environment with the react dependency. I would highly appreciate any suggestions. Thanks! |
There is something I don't understand: the rule is not enabled by default (it is not recommended). Thus, the rule should only be enabled if the project use React. Why did you enable it in the first place? |
Maybe the documentation could be improved, but this rule isn't meant for non-react projects, so I don't think it's a bug on our side. |
I agree with @ematipico I'm all for saving user's time configuring projects, and maybe we could come up with some really good heuristics to auto detect what kind of project biome is operating on, but heuristics are not perfect. If anything, it would probably be better to ask the user for that info in Would it make sense to have more collections of rules similar to how we currently have recommended rules? eg. |
There's an RFC for that, you can find it from the pinned umbrella issue "Biome developments" |
@Conaclos because I am an idiot apparently. I had |
Environment information
What happened?
The following sample NestJS snippet triggers the
useHookAtTopLevel
thinkinguseGlobalInterceptors
is a React hook.Expected result
It should not raise any warning/error
Code of Conduct
The text was updated successfully, but these errors were encountered: