Repository: facebook/react
Pull request: Fix false positive lint error with large number of branches 

…trc.js to use es2020.

<!--
  Thanks for submitting a pull request!
  We appreciate you spending the time to work on these changes. Please provide enough information so that others can review your pull request. The three fields below are mandatory.

  Before submitting a pull request, please make sure the following is done:

  1. Fork [the repository](https://github.com/facebook/react) and create your branch from `main`.
  2. Run `yarn` in the repository root.
  3. If you've fixed a bug or added code that should be tested, add tests!
  4. Ensure the test suite passes (`yarn test`). Tip: `yarn test --watch TestName` is helpful in development.
  5. Run `yarn test --prod` to test in the production environment. It supports the same options as `yarn test`.
  6. If you need a debugger, run `yarn debug-test --watch TestName`, open `chrome://inspect`, and press "Inspect".
  7. Format your code with [prettier](https://github.com/prettier/prettier) (`yarn prettier`).
  8. Make sure your code lints (`yarn lint`). Tip: `yarn linc` to only check changed files.
  9. Run the [Flow](https://flowtype.org/) type checks (`yarn flow`).
  10. If you haven't already, complete the CLA.

  Learn more about contributing: https://reactjs.org/docs/how-to-contribute.html
-->

## 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?

<!--
  Demonstrate the code is solid. Example: The exact commands you ran and their output, screenshots / videos if the pull request changes the user interface.
  How exactly did you verify that your PR solves the issue you wanted to solve?
  If you leave this empty, your PR will very likely be closed.
-->
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.
![image](https://user-images.githubusercontent.com/63068182/162086280-bae69c58-2285-4813-a10a-9c0d03a8a770.png)

When I run all tests in ESLintRulesOfHooks-test.js, everything passes.
![image](https://user-images.githubusercontent.com/63068182/162086653-d428aec6-b953-4d7b-9020-7647259ff629.png)

Unfortunately, when I ran yarn test --prod, I got several errors that were unrelated to ESLintRulesOfHooks. I am not sure if this is normal. 

Changed files:
filename: packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js
patch: @@ -325,6 +325,75 @@ const tests = {
         useHook();
       }
     `,
+    `
+      // Valid because the neither the conditions before or after the hook affect the hook call
+      // Failed prior to implementing BigInt because pathsFromStartToEnd and allPathsFromStartToEnd were too big and had rounding errors
+      const useSomeHook = () => {};
+
+      const SomeName = () => {
+        const filler = FILLER ?? FILLER ?? FILLER;
+        const filler2 = FILLER ?? FILLER ?? FILLER;
+        const filler3 = FILLER ?? FILLER ?? FILLER;
+        const filler4 = FILLER ?? FILLER ?? FILLER;
+        const filler5 = FILLER ?? FILLER ?? FILLER;
+        const filler6 = FILLER ?? FILLER ?? FILLER;
+        const filler7 = FILLER ?? FILLER ?? FILLER;
+        const filler8 = FILLER ?? FILLER ?? FILLER;
+
+        useSomeHook();
+
+        if (anyConditionCanEvenBeFalse) {
+          return null;
+        }
+
+        return (
+          <React.Fragment>
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+            {FILLER ? FILLER : FILLER}
+          </React.Fragment>
+        );
+      };
+    `,
     `
       // Valid because the neither the condition nor the loop affect the hook call.
       function App(props) {

filename: packages/eslint-plugin-react-hooks/src/RulesOfHooks.js
patch: @@ -5,6 +5,7 @@
  * LICENSE file in the root directory of this source tree.
  */
 
+/* global BigInt */
 /* eslint-disable no-for-of-loops/no-for-of-loops */
 
 'use strict';
@@ -175,7 +176,7 @@ export default {
               cyclic.add(cyclicSegment);
             }
 
-            return 0;
+            return BigInt('0');
           }
 
           // add the current segment to pathList
@@ -187,19 +188,19 @@ export default {
           }
 
           if (codePath.thrownSegments.includes(segment)) {
-            paths = 0;
+            paths = BigInt('0');
           } else if (segment.prevSegments.length === 0) {
-            paths = 1;
+            paths = BigInt('1');
           } else {
-            paths = 0;
+            paths = BigInt('0');
             for (const prevSegment of segment.prevSegments) {
               paths += countPathsFromStart(prevSegment, pathList);
             }
           }
 
           // If our segment is reachable then there should be at least one path
           // to it from the start of our code path.
-          if (segment.reachable && paths === 0) {
+          if (segment.reachable && paths === BigInt('0')) {
             cache.delete(segment.id);
           } else {
             cache.set(segment.id, paths);
@@ -246,7 +247,7 @@ export default {
               cyclic.add(cyclicSegment);
             }
 
-            return 0;
+            return BigInt('0');
           }
 
           // add the current segment to pathList
@@ -258,11 +259,11 @@ export default {
           }
 
           if (codePath.thrownSegments.includes(segment)) {
-            paths = 0;
+            paths = BigInt('0');
           } else if (segment.nextSegments.length === 0) {
-            paths = 1;
+            paths = BigInt('1');
           } else {
-            paths = 0;
+            paths = BigInt('0');
             for (const nextSegment of segment.nextSegments) {
               paths += countPathsToEnd(nextSegment, pathList);
             }

filename: scripts/rollup/validate/eslintrc.cjs.js
patch: @@ -7,6 +7,7 @@ module.exports = {
   },
   globals: {
     // ES 6
+    BigInt: 'readonly',
     Map: 'readonly',
     Set: 'readonly',
     Proxy: 'readonly',

filename: scripts/rollup/validate/eslintrc.cjs2015.js
patch: @@ -7,6 +7,7 @@ module.exports = {
   },
   globals: {
     // ES 6
+    BigInt: 'readonly',
     Map: 'readonly',
     Set: 'readonly',
     Proxy: 'readonly',