fix(linter/prefer-for-of): false positive with diff member expression#13201
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
There was a problem hiding this comment.
Pull Request Overview
This PR fixes a false positive in the prefer-for-of linter rule where it incorrectly flagged for-loops that access different objects with similar member expression patterns. The fix improves the comparison logic to accurately determine if the same array is being accessed in both the loop condition and body.
- Enhanced expression comparison to use
is_same_expressionutility instead of simple string matching - Modified the rule to track both array name and expression for more accurate analysis
- Added comprehensive test cases for deeply nested object access patterns
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| crates/oxc_linter/src/rules/typescript/prefer_for_of.rs | Enhanced the core logic to properly compare member expressions using AST-based comparison instead of string matching |
| crates/oxc_linter/src/snapshots/typescript_prefer_for_of.snap | Added snapshot test outputs for new test cases involving deeply nested object access |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
You can also share your feedback on Copilot code review for a chance to win a $100 gift card. Take the survey.
CodSpeed Instrumentation Performance ReportMerging #13201 will not alter performanceComparing Summary
Footnotes |
023fac1 to
3b6ab99
Compare
Merge activity
|
3b6ab99 to
163dbea
Compare

fixes #13200