fix(lint): noArrayIndexKey should flag index anywhere in template#8968
fix(lint): noArrayIndexKey should flag index anywhere in template#8968LouisLau-art wants to merge 2 commits intobiomejs:mainfrom
Conversation
🦋 Changeset detectedLatest commit: 93789c6 The changes in this PR will be included in the next version bump. This PR includes changesets to release 13 packages
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 |
WalkthroughReworks 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
🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches🧪 Generate unit tests (beta)
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. Comment |
|
Please add a changeset and restore our PR template |
CodSpeed Performance ReportMerging this PR will not alter performanceComparing Summary
Footnotes
|
|
Thanks for the reminder. I’ll add a changeset and restore the PR template format in this PR. |
|
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). |
dyc3
left a comment
There was a problem hiding this comment.
Looks good. Just fix the lints from clippy
|
Thanks, I’ll take care of the remaining Clippy lints in a follow-up commit. |
Summary
Fixes #8812.
lint/suspicious/noArrayIndexKeypreviously 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
keyexpressions (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_keycargo test -p biome_js_formatterDocs
No docs change required; this is a behavior fix for an existing lint rule.