fix(react-doctor): detect index-derived key locals#179
Open
JW-Rami wants to merge 1 commit intomillionco:mainfrom
Open
fix(react-doctor): detect index-derived key locals#179JW-Rami wants to merge 1 commit intomillionco:mainfrom
JW-Rami wants to merge 1 commit intomillionco:mainfrom
Conversation
|
@JW-Rami is attempting to deploy a commit to the Million Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Detect
no-array-index-as-keywhen a JSXkeyreferences a local constant whose initializer is derived from the.map()index parameter.Why
The rule already caught inline template literals such as
key={${item.id}-${index}}, but the same expression could be hoisted intoconst itemKey = ...and then used askey={itemKey}without a diagnostic.How to test
nr testnr lintnr typechecknr formatNote
Medium Risk
Expands the
no-array-index-as-keyrule to follow simple local variable initializers inside.map()callbacks, which can introduce new diagnostics (potentially false positives/negatives) in existing codebases.Overview
Improves
no-array-index-as-keyto also flagkey={itemKey}patterns whereitemKeyis a local variable derived from a.map()index parameter (including custom index parameter names).The rule now locates the enclosing
.map()callback, tracks its index parameter, and (when thekeyexpression is an identifier) inspects top-level variable initializers in that callback while stopping at nested function boundaries to avoid accidental cross-scope resolution.Adds regression tests covering index-derived locals, stable-field-only locals, and nested function shadowing.
Reviewed by Cursor Bugbot for commit 5afe509. Bugbot is set up for automated code reviews on this repo. Configure here.