Skip to content

fix(react-doctor): detect index-derived key locals#179

Open
JW-Rami wants to merge 1 commit intomillionco:mainfrom
JW-Rami:rami/trace-index-key-constant
Open

fix(react-doctor): detect index-derived key locals#179
JW-Rami wants to merge 1 commit intomillionco:mainfrom
JW-Rami:rami/trace-index-key-constant

Conversation

@JW-Rami
Copy link
Copy Markdown

@JW-Rami JW-Rami commented May 8, 2026

What

Detect no-array-index-as-key when a JSX key references 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 into const itemKey = ... and then used as key={itemKey} without a diagnostic.

How to test

  • nr test
  • nr lint
  • nr typecheck
  • nr format

Note

Medium Risk
Expands the no-array-index-as-key rule 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-key to also flag key={itemKey} patterns where itemKey is 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 the key expression 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.

@vercel
Copy link
Copy Markdown

vercel Bot commented May 8, 2026

@JW-Rami is attempting to deploy a commit to the Million Team on Vercel.

A member of the Team first needs to authorize it.

@JW-Rami JW-Rami marked this pull request as ready for review May 8, 2026 16:59
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.

1 participant