Fix false positive lint error with large number of branches #24287
Merged
gaearon merged 5 commits intofacebook:mainfrom Apr 7, 2022
scyron6:bug-24279-conditional-hook
Merged
Fix false positive lint error with large number of branches #24287gaearon merged 5 commits intofacebook:mainfrom scyron6:bug-24279-conditional-hook
gaearon merged 5 commits intofacebook:mainfrom
scyron6:bug-24279-conditional-hook
Conversation
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
…trc.js to use es2020.
Summary
Fixes #24279. JavaScript could not handle the large integer when there were numerous conditional statements before and after the hook. This was causing rounding errors which resulted in a conditional being evaluated incorrectly. I switched the functions to use BigInts instead and updated the eslintrc.js. If using BigInts is not acceptable, I'll be happy to try and find a different solution.
How did you test this change?
The user who created the issue linked to a repository that showed the bug. I copied that exact code and pasted into the tests file. This test now passes.
Link to repository: https://github.com/SanderRonde/eslint-hook-bug
Now when I open that file in my local instance, there is no error message for the hook.

When I run all tests in ESLintRulesOfHooks-test.js, everything passes.

Unfortunately, when I ran yarn test --prod, I got several errors that were unrelated to ESLintRulesOfHooks. I am not sure if this is normal.