Skip to content

fix(linter/no-array-index-key): false positive when index is inside an expression within a template literal#21123

Merged
camc314 merged 2 commits intooxc-project:mainfrom
babu-ch:fix/no-array-index-key-template-literal-false-positive
Apr 7, 2026
Merged

fix(linter/no-array-index-key): false positive when index is inside an expression within a template literal#21123
camc314 merged 2 commits intooxc-project:mainfrom
babu-ch:fix/no-array-index-key-template-literal-false-positive

Conversation

@babu-ch
Copy link
Copy Markdown
Contributor

@babu-ch babu-ch commented Apr 7, 2026

Closes #21110

Related: #21012

Summary

The TemplateLiteral branch in expression_uses_index was calling expression_uses_index recursively, so it detected index even when wrapped in a binary expression or function call inside ${...}. ESLint only checks for direct index references, so replaced with is_index_reference.

ESLint comparison (inside template literals)

Pattern ESLint oxlint (before) oxlint (after)
`abc${index}` error error error
`${item.type + index}` pass error pass
`abc${String(index)}` pass error pass
`abc${index.toString()}` pass error pass

@babu-ch babu-ch requested a review from camc314 as a code owner April 7, 2026 12:21
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Apr 7, 2026
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Apr 7, 2026

Merging this PR will not alter performance

✅ 4 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing babu-ch:fix/no-array-index-key-template-literal-false-positive (7eefd29) with main (15574bc)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports.

Copy link
Copy Markdown
Contributor

@camc314 camc314 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@camc314 camc314 merged commit edd0865 into oxc-project:main Apr 7, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-linter Area - Linter C-bug Category - Bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

linter: react/no-array-index-key false positive when index appears inside a template literal expression

2 participants