react
react copied to clipboard
react-hooks/rules-of-hooks: detect issues in property definitions
Summary
As detailed in #27431, with the eslint parser set to @typescript-eslint/parser v5 or newer, this code was no longer being flagged by eslint-plugin-react-hooks rules-of-hooks:
import { useState } from 'react';
class Test {
useHook = () => {
useState(); // should be an error
}
}
This was due to a change in @typescript-eslint/parser v5, where the AST node type ClassProperty was renamed to PropertyDefinition. So the fix is to also check for PropertyDefinition in the lint rule.
Open question: Is this considered a breaking change? These violations would have been flagged with @typescript-eslint/parser v4 and older, but if a repo upgraded to >= v5, new violations could have been introduced, which would cause build breaks when the rule is updated.
Fixes #27431
How did you test this change?
- Updated the
rules-of-hookstests to run with more parsers (including typescript-eslint v4 and v5) and verified that they pass - Made the same change in the installed copy of
eslint-plugin-react-hooksin another repo (wasn't sure how to build the plugin from my local react repo) and verified the error was flagged
Hi @ecraig12345!
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!
Comparing: d900fadbf9017063fecb2641b7e99303b82a6f17...3c30b39e731a76bf97b98144e38c8f8f89e81e88
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 | = | 167.55 kB | 167.55 kB | = | 52.14 kB | 52.14 kB |
| oss-experimental/react-dom/cjs/react-dom.production.min.js | = | 176.21 kB | 176.21 kB | = | 54.84 kB | 54.84 kB |
| facebook-www/ReactDOM-prod.classic.js | = | 564.39 kB | 564.39 kB | = | 99.37 kB | 99.37 kB |
| facebook-www/ReactDOM-prod.modern.js | = | 548.11 kB | 548.11 kB | = | 96.45 kB | 96.45 kB |
Significant size changes
Includes any change greater than 0.2%:
(No significant changes)
Generated by :no_entry_sign: dangerJS against 3c30b39e731a76bf97b98144e38c8f8f89e81e88
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.
bump
PR has merge conflicts. Can you rebase this onto latest main?
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.
bump
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!