Skip to content

[eslint-plugin-react-hooks] Remove the comma along with an Effect Event dependency - #38448

Open
pdobrowolski99 wants to merge 1 commit into
react:mainfrom
pdobrowolski99:fix/exhaustive-deps-effect-event-removal
Open

pdobrowolski99 wants to merge 1 commit into
react:mainfrom
pdobrowolski99:fix/exhaustive-deps-effect-event-removal

Conversation

@pdobrowolski99

Copy link
Copy Markdown

Summary

Fixes #38442

The "Remove the dependency" suggestion that exhaustive-deps offers for an Effect Event removed only the identifier and left its comma behind. [a, onTick, b] became [a, , b], a sparse array that no-sparse-arrays reports and that exhaustive-deps then skips, and [a, onTick] became [a, ]. With enableDangerousAutofixThisMayCauseInfiniteLoops the same edit is applied as an autofix.

The suggestion now removes the element together with its separating comma:

Before Previous suggestion Now
[onTick, b] [, b] [b]
[a, onTick, b] [a, , b] [a, b]
[a, onTick] [a, ] [a]
[a, onTick,] [a, ,] [a,]
[onTick,] [,] []

In a multi-line array the element's line goes with it. Two adjacent Effect Events each get a suggestion that removes only that one.

How did you test this change?

  • Added cases to ESLintRuleExhaustiveDeps-test.js for the first, middle and last element, a trailing comma, a multi-line array, two adjacent Effect Events and the autofix option. On main they fail in all 12 configurations (84 failures); with the change they pass.
  • All eslint-plugin-react-hooks tests pass (5172), as well as yarn workspace eslint-plugin-react-hooks typecheck, yarn linc and yarn prettier.
  • Built the plugin with yarn build eslint-plugin-react-hooks and applied the suggestion and the autofix with ESLint 9.39.5 to the arrays from the issue, plus a commented and a multi-line one. None of them leaves a hole or a stray comma (7.1.1 from npm got 8 of 9 wrong).

…nt dependency

The "Remove the dependency" suggestion for an Effect Event removed only
the identifier, so `[a, onTick, b]` became the sparse array `[a, , b]`
and `[a, onTick]` became `[a, ]`. The suggestion now removes the
element together with its separating comma, and keeps a trailing comma
when the array had one.

Fixes react#38442
@meta-cla

meta-cla Bot commented Nov 29, 2026

Copy link
Copy Markdown

Hi @pdobrowolski99!

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!

@github-actions

Copy link
Copy Markdown

A size report will appear here when the build finishes.

Generated by sizebot against 41b39ed

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[eslint-plugin-react-hooks] exhaustive-deps leaves sparse array holes when removing an Effect Event from a dependency list

1 participant