Skip to content

fix(linter/prefer-at): wrap expressions in parentheses when needed for member access#16643

Merged
graphite-app[bot] merged 1 commit intomainfrom
c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access
Dec 9, 2025
Merged

fix(linter/prefer-at): wrap expressions in parentheses when needed for member access#16643
graphite-app[bot] merged 1 commit intomainfrom
c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access

Conversation

@camc314
Copy link
Copy Markdown
Contributor

@camc314 camc314 commented Dec 9, 2025

No description provided.

@camc314 camc314 force-pushed the c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access branch from c840873 to 0ccef79 Compare December 9, 2025 11:26
@github-actions github-actions bot added A-linter Area - Linter C-bug Category - Bug labels Dec 9, 2025
Copy link
Copy Markdown
Contributor Author

camc314 commented Dec 9, 2025


How to use the Graphite Merge Queue

Add either label to this PR to merge it via the merge queue:

  • 0-merge - adds this PR to the back of the merge queue
  • hotfix - for urgent hot fixes, skip the queue and merge this PR next

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.

@camc314 camc314 marked this pull request as ready for review December 9, 2025 11:28
Copilot AI review requested due to automatic review settings December 9, 2025 11:28
@graphite-app
Copy link
Copy Markdown
Contributor

graphite-app bot commented Dec 9, 2025

Merge activity

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Dec 9, 2025

CodSpeed Performance Report

Merging #16643 will not alter performance

Comparing c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access (6cddbe7) with main (678e43b)

Summary

✅ 4 untouched
⏩ 41 skipped1

Footnotes

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

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_precedence function from no_extra_boolean_cast rule to shared utils/unicorn.rs for reuse
  • Added precedence checking in prefer_at rule's check_lodash_last function 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.

@graphite-app graphite-app bot force-pushed the c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access branch from 0ccef79 to 6cddbe7 Compare December 9, 2025 11:32
@graphite-app graphite-app bot merged commit 6cddbe7 into main Dec 9, 2025
21 checks passed
@graphite-app graphite-app bot deleted the c/12-09-fix_linter_prefer-at_wrap_expressions_in_parentheses_when_needed_for_member_access branch December 9, 2025 11:37
Copilot AI pushed a commit that referenced this pull request Dec 10, 2025
taearls pushed a commit to taearls/oxc that referenced this pull request Dec 11, 2025
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.

2 participants