Skip to content
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

react-hooks/rules-of-hooks: Add support for do/while loops #28714

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

tyxla
Copy link

@tyxla tyxla commented Apr 2, 2024

Summary

Currently, react-hooks/rules-of-hooks does not support do/while loops - I've also reported this in #28713.

This PR takes a stab at adding support for do/while by following the same logic we already have for detecting while loops.

After this PR, any hooks called inside a do/while loop will be considered invalid.

We're also adding some unit tests to confirm that the behavior is working as expected.

Fixes #28713.

How did you test this change?

I've added unit tests that cover the case and verified that they pass by running:

yarn test packages/eslint-plugin-react-hooks/__tests__/ESLintRulesOfHooks-test.js --watch

I've also verified that the rest of the tests continue to pass by running:

yarn test

and

yarn test --prod

@facebook-github-bot
Copy link

Hi @tyxla!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at [email protected]. Thanks!

@tyxla tyxla changed the title Fix/rule of hooks do while react-hooks/rules-of-hooks: Add support for do/while loops Apr 2, 2024
@react-sizebot
Copy link

Comparing: 6e65010...33a8918

Critical size changes

Includes critical production bundles, as well as any change greater than 2%:

Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable/react-dom/cjs/react-dom.production.min.js = 177.10 kB 177.10 kB = 55.05 kB 55.05 kB
oss-experimental/react-dom/cjs/react-dom.production.min.js = 172.94 kB 172.94 kB = 53.91 kB 53.91 kB
facebook-www/ReactDOM-prod.classic.js = 592.68 kB 592.68 kB = 103.96 kB 103.96 kB
facebook-www/ReactDOM-prod.modern.js = 574.37 kB 574.37 kB = 100.98 kB 100.98 kB
test_utils/ReactAllWarnings.js Deleted 64.93 kB 0.00 kB Deleted 16.24 kB 0.00 kB

Significant size changes

Includes any change greater than 0.2%:

Expand to show
Name +/- Base Current +/- gzip Base gzip Current gzip
oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js +0.27% 92.68 kB 92.93 kB +0.02% 21.79 kB 21.80 kB
oss-stable/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js +0.27% 92.68 kB 92.93 kB +0.02% 21.79 kB 21.80 kB
oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.production.js +0.27% 92.83 kB 93.08 kB +0.02% 21.81 kB 21.82 kB
oss-stable-semver/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js +0.27% 93.66 kB 93.91 kB +0.02% 21.99 kB 21.99 kB
oss-stable/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js +0.27% 93.66 kB 93.91 kB +0.02% 21.99 kB 21.99 kB
oss-experimental/eslint-plugin-react-hooks/cjs/eslint-plugin-react-hooks.development.js +0.27% 93.81 kB 94.06 kB +0.01% 22.01 kB 22.01 kB
test_utils/ReactAllWarnings.js Deleted 64.93 kB 0.00 kB Deleted 16.24 kB 0.00 kB

Generated by 🚫 dangerJS against 33a8918

@tyxla
Copy link
Author

tyxla commented Apr 17, 2024

@eps1lon I noticed you've been working on the ESLint rules, will you have a chance to take a look? Thanks 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: react-hooks/rules-of-hooks does not support do/while loops
3 participants