react icon indicating copy to clipboard operation
react copied to clipboard

react-hooks/rules-of-hooks: detect issues in property definitions

Open ecraig12345 opened this issue 2 years ago • 7 comments

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-hooks tests 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-hooks in another repo (wasn't sure how to build the plugin from my local react repo) and verified the error was flagged

ecraig12345 avatar Sep 28 '23 20:09 ecraig12345

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!

facebook-github-bot avatar Sep 28 '23 20:09 facebook-github-bot

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

react-sizebot avatar Sep 29 '23 21:09 react-sizebot

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.

github-actions[bot] avatar Apr 06 '24 02:04 github-actions[bot]

bump

ecraig12345 avatar Apr 08 '24 22:04 ecraig12345

PR has merge conflicts. Can you rebase this onto latest main?

eps1lon avatar Jun 26 '24 10:06 eps1lon

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.

github-actions[bot] avatar Sep 24 '24 11:09 github-actions[bot]

bump

hmhealey avatar Sep 24 '24 16:09 hmhealey

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.

github-actions[bot] avatar Dec 23 '24 17:12 github-actions[bot]

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!

github-actions[bot] avatar Dec 30 '24 18:12 github-actions[bot]