Skip to content

fix(linter/react/jsx-key): only check direct members of array literals - #29249

Closed
studiokvc wants to merge 2 commits into
oxc-project:mainfrom
studiokvc:fix/jsx-key-direct-array-members
Closed

studiokvc wants to merge 2 commits into
oxc-project:mainfrom
studiokvc:fix/jsx-key-direct-array-members

Conversation

@studiokvc

Copy link
Copy Markdown

Closes #29246

react/jsx-key reported JSX nested inside an array element, e.g. the conditional in [needed ? 1 : undefined, needed ? <Counter onCount={set} /> : null] as const. eslint-plugin-react only checks JSX elements that are direct members of the array literal, so this is a false positive compared to it.

When walking up from the JSX node, the array case now only reports if the array's child is the JSX element itself (possibly parenthesized). Elements directly in an array are still reported ([<App />], [(<App />)], cond ? [<App />] : null), and the iterator callbacks (.map(x => cond ? <A /> : <B />)) are unchanged.

Tests: the issue's example, [cond ? <App /> : null] and [cond && <App />] as pass cases (they fail without the change), and [(<App />)] / cond ? [<App />] : null as fail cases, with the snapshot updated. cargo test -p oxc_linter --lib react passes (114), cargo fmt and cargo clippy -p oxc_linter are clean.

AI disclosure: written with Claude (Claude Code). I reviewed the change and ran the tests above.

Closes oxc-project#29246

Co-authored-by: Claude <noreply@anthropic.com>

Signed-off-by: Studio KVC <studiokvc@gmail.com>
Co-authored-by: Claude <noreply@anthropic.com>

Signed-off-by: Studio KVC <studiokvc@gmail.com>
@studiokvc
studiokvc requested a review from camc314 as a code owner November 10, 2026 20:10
@camc314

camc314 commented Nov 11, 2026

Copy link
Copy Markdown
Contributor

Hi! Thanks for working on this.

The linked issue has been fixed by #29294, so this PR is no longer needed.

Thanks!

@camc314 camc314 closed this Nov 11, 2026
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.

linter: react/jsx-key reports a conditional JSX element in an array literal, unlike eslint-plugin-react

2 participants