fix(linter/prefer-at): wrap expressions in parentheses when needed for member access#16643
Conversation
c840873 to
0ccef79
Compare
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. |
Merge activity
|
CodSpeed Performance ReportMerging #16643 will not alter performanceComparing Summary
Footnotes
|
…r member access (#16643)
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug in the unicorn/prefer-at linter rule where TypeScript type assertions and other low-precedence expressions were not properly wrapped in parentheses when transformed to use .at() method. It also refactors the get_precedence utility function to be shared across multiple linter rules.
Key Changes:
- Extracted
get_precedencefunction fromno_extra_boolean_castrule to sharedutils/unicorn.rsfor reuse - Added precedence checking in
prefer_atrule'scheck_lodash_lastfunction to wrap low-precedence expressions in parentheses - Added test cases demonstrating correct handling of TypeScript type assertions
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
crates/oxc_linter/src/utils/unicorn.rs |
Adds the get_precedence utility function with comprehensive documentation for determining when parentheses are needed during code transformations |
crates/oxc_linter/src/rules/unicorn/prefer_at.rs |
Applies precedence checking to wrap expressions like [] as [] in parentheses when converting _.last(expr) to expr.at(-1), preventing invalid output like [] as [].at(-1) |
crates/oxc_linter/src/rules/eslint/no_extra_boolean_cast.rs |
Removes the local get_precedence function and updates imports to use the shared utility instead |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
0ccef79 to
6cddbe7
Compare

No description provided.