Repository navigation
[eslint-plugin-react-hooks] Remove the comma along with an Effect Event dependency - #38448
pdobrowolski99 wants to merge 1 commit into
Conversation
…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
|
Hi @pdobrowolski99! Thank you for your pull request and welcome to our community. Action RequiredIn 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. ProcessIn 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 If you have received this in error or have any questions, please contact us at [email protected]. Thanks! |
Summary
Fixes #38442
The "Remove the dependency" suggestion that
exhaustive-depsoffers for an Effect Event removed only the identifier and left its comma behind.[a, onTick, b]became[a, , b], a sparse array thatno-sparse-arraysreports and thatexhaustive-depsthen skips, and[a, onTick]became[a, ]. WithenableDangerousAutofixThisMayCauseInfiniteLoopsthe same edit is applied as an autofix.The suggestion now removes the element together with its separating comma:
[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?
ESLintRuleExhaustiveDeps-test.jsfor the first, middle and last element, a trailing comma, a multi-line array, two adjacent Effect Events and the autofix option. Onmainthey fail in all 12 configurations (84 failures); with the change they pass.eslint-plugin-react-hookstests pass (5172), as well asyarn workspace eslint-plugin-react-hooks typecheck,yarn lincandyarn prettier.yarn build eslint-plugin-react-hooksand 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.1from npm got 8 of 9 wrong).