-
-
Notifications
You must be signed in to change notification settings - Fork 892
fix(linter): react rules of hooks false positive #9807
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
Closed
hulin32
wants to merge
4
commits into
oxc-project:main
from
hulin32:fix/9795-react-rules-of-hooks-false-positive
Closed
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
4022861
fix: initial fix for react-hooks/rules-of-hooks false positive of
hulin32 d0b7f52
keep current test cases
hulin32 11f1b76
fix: add one more test to cover ternary condition in if clause
hulin32 93213fd
[autofix.ci] apply automated fixes
autofix-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
hmm while this solution works, i'm not convinced it's the ideal solution?
Ideally, i think we would change the cfg to represent that the
testof anifstatement is always represented as visited.We would look to change the code inside
visit_if_statementto something like: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.
This is much much more elegant 👍, I will close my MR, thx for sharing
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.
Any possible to give a bit more context why this can fix the issue?
I will look into the codes, still trying to understand the whole process in OXC.
Thanks for sharing again
Uh oh!
There was an error while loading. Please reload this page.
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.
yeah sure. firstly thanks for trying to fix it, we appreciate the contributions!
so the control flow graph logic of this codebase is (imo, i'm sure others may disagree 🙂) some of the most complex logical code.
From my understanding, the problem was that the "test" of the IfStatement, was being marked as conditionally visited (which is incorrect as the test is always evaluated).
by changing that logic in oxc_semantic, we changed the CFG, to represent that the test expression is always visited.
i'll try and put up a PR tomorrow, with a more detailed explanation on why those exact changes fix this issue
(on mobile atm)
thanks!