-
-
Notifications
You must be signed in to change notification settings - Fork 524
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
fix(useHookAtTopLevel): avoid diagnostics on non react projects #3826
fix(useHookAtTopLevel): avoid diagnostics on non react projects #3826
Conversation
CodSpeed Performance ReportMerging #3826 will degrade performances by 6.34%Comparing Summary
Benchmarks breakdown
|
@dyc3 Should I bump the version of the rule? And is there a way to simulate dependencies on the diagnostics ran by declare_lint_rule?
|
No, the version field is the version of biome in which the rule became available, so leave that as is.
I have no idea, I've never had to do that before. |
crates/biome_js_analyze/src/lint/correctness/use_hook_at_top_level.rs
Outdated
Show resolved
Hide resolved
Sorry if I missed something, but shouldn't we also at least look at the I work on libraries where we sometimes use react for demo pages, development tools and/or tests. Those are generally not exposed to library users, and thus React is often only declared as a devDependency. I'm under the impression that:
Only applies to the |
Please, note that I added a comment in the issue. |
I didn't think about that use case and I agree we should look at devDependencies too. Although I'm also waiting for an answer to the comment in the issue to understand better if what I tried to do here is really needed. |
ce26087
to
b5aeafe
Compare
EDIT: In my first version of this comment, I forgot that the absence of a
Yes thanks, I read the issue yet still added a comment in this PR just in case it turned out to be merged in the near future, as I'm only checking here sporadically. I share the same linked interrogation, and I fear edge cases where that heuristic would produce false negatives.
Thank you! Just to go further through edge cases I'm wondering about: some project could theoretically have it only as an optional dependency or a peer dependency (like react-related libraries for example), or even not relying on a package manager to set-up react. E.g., I've worked with developers only relying on minified library bundles added as script tags in their HTML - and most browsers now also allows directly importing modules at runtime. Yet all of them could still be using biome and react, but maybe that's an unsupported usage? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Blocking for now, we haven't identified what's the real bug. Let's first discuss it in the relative issue.
I am going to close it for now, as it's up to the developer to enable this rule in this project. We are going to provide a better system in the future, possibly for Biome v2.0, so users can enable framework-related rules via configuration. |
Summary
Closes #3476
To avoid reporting diagnostics of this hook on non react projects I added a check against the
package.json
to findreact
dependency. This should help on many of the edge cases. Like the methods from NestJS app starting with "use".Test Plan
I need a way to run the snapshots as if the tests were running with the 'react' dependency. The CI tests should pass once this is done.
Quick Test screenshots