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: detect issues in property definitions #27435

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

Conversation

ecraig12345
Copy link

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

@facebook-github-bot
Copy link

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!

@react-sizebot
Copy link

Comparing: d900fad...3c30b39

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 🚫 dangerJS against 3c30b39

Copy link

github-actions bot commented Apr 6, 2024

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 github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Apr 6, 2024
@ecraig12345
Copy link
Author

bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Apr 10, 2024
@eps1lon
Copy link
Collaborator

eps1lon commented Jun 26, 2024

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

Copy link

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 github-actions bot added the Resolution: Stale Automatically closed due to inactivity label Sep 24, 2024
@hmhealey
Copy link

bump

@github-actions github-actions bot removed the Resolution: Stale Automatically closed due to inactivity label Sep 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
5 participants