Skip to content

fix(lint): noArrayIndexKey should flag index anywhere in template#8968

Open
LouisLau-art wants to merge 2 commits intobiomejs:mainfrom
LouisLau-art:fix/noArrayIndexKey-template-order
Open

fix(lint): noArrayIndexKey should flag index anywhere in template#8968
LouisLau-art wants to merge 2 commits intobiomejs:mainfrom
LouisLau-art:fix/noArrayIndexKey-template-order

Conversation

@LouisLau-art
Copy link
Contributor

@LouisLau-art LouisLau-art commented Feb 5, 2026

Summary

Fixes #8812.

lint/suspicious/noArrayIndexKey previously only tracked the last identifier found in a template/binary expression (and could skip reporting when templates mixed identifier and non-identifier expressions).

This update collects all reference identifiers from key expressions (template, binary, parenthesized) and reports when any of them resolves to the array-index parameter.

Added test coverage for cases like:

  • key={`${index}-${item}`}
  • key={`${item.title}-${index}`}
  • key={index + item}

AI assistance notice: this PR was prepared with AI assistance and manually verified before submission.

Test Plan

  • cargo test -p biome_js_analyze -- no_array_index_key
  • cargo test -p biome_js_formatter

Docs

No docs change required; this is a behavior fix for an existing lint rule.

@changeset-bot
Copy link

changeset-bot bot commented Feb 5, 2026

🦋 Changeset detected

Latest commit: 93789c6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 5, 2026

Walkthrough

Reworks the noArrayIndexKey lint rule to gather multiple reference identifiers from key expressions via a new collect_reference_identifiers routine (handles identifiers, template expressions, binary expressions, and parenthesised expressions). For each candidate it resolves the binding to a function parameter and traces to the surrounding call to determine whether the parameter is an array index (is_array_method_index). Diagnostic state construction is adjusted to preserve the React.cloneElement path; earlier recursive cap_array_index_value traversal was removed and error paths simplified. Adds three test components covering template and binary key expressions.

Suggested reviewers

  • ematipico
  • dyc3
🚥 Pre-merge checks | ✅ 4
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely summarises the main change: fixing the noArrayIndexKey lint rule to detect index usage anywhere in templates, not just the last position.
Description check ✅ Passed The description is well-structured and directly related to the changeset, explaining the fix, test cases, and verification steps.
Linked Issues check ✅ Passed The PR successfully addresses issue #8812 by collecting all reference identifiers from key expressions and reporting when any resolves to the array-index parameter, preventing false negatives.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the noArrayIndexKey lint rule: implementation refactor, test coverage additions, and changelog entry are all in-scope.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

No actionable comments were generated in the recent review. 🎉


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@dyc3
Copy link
Contributor

dyc3 commented Feb 6, 2026

Please add a changeset and restore our PR template

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 6, 2026

CodSpeed Performance Report

Merging this PR will not alter performance

Comparing LouisLau-art:fix/noArrayIndexKey-template-order (93789c6) with main (db0da5c)

Summary

✅ 58 untouched benchmarks
⏩ 95 skipped benchmarks1

Footnotes

  1. 95 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.

@LouisLau-art
Copy link
Contributor Author

Thanks for the reminder. I’ll add a changeset and restore the PR template format in this PR.

@LouisLau-art
Copy link
Contributor Author

Addressed both points: I added a changeset in this branch and restored the PR description structure using the project PR template sections (Summary/Test Plan/Docs).

Copy link
Contributor

@dyc3 dyc3 left a comment

Choose a reason for hiding this comment

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

Looks good. Just fix the lints from clippy

@LouisLau-art
Copy link
Contributor Author

Thanks, I’ll take care of the remaining Clippy lints in a follow-up commit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 lint/suspicious/noArrayIndexKey false negative when re-ordering value and index in template string

2 participants