-
-
Notifications
You must be signed in to change notification settings - Fork 724
fix: simplify parens check in exponentiation expression handling #7341
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
WalkthroughThe lint in crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs now uses a boolean to decide parentheses and wraps the newly created exponentiation expression directly when required. does_exponentiation_expression_need_parens changed from Option<(bool, Option)> to Option, removing parent-node handling. Call sites use the boolean to conditionally wrap new_node, and no public APIs were changed. ✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
Inspired by #7336 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs (3)
154-158
: Wrap-the-child approach is spot on; tiny simplification availableYou can avoid the
if let Some(true)
pattern and read a little cleaner withunwrap_or(false)
(semantics unchanged, as the helper never returnsSome(false)
).- let new_node = if let Some(true) = does_exponentiation_expression_need_parens(node) { + let new_node = if does_exponentiation_expression_need_parens(node).unwrap_or(false) { make::parenthesized(new_node).into() } else { new_node };
173-177
: Rustdoc is now misleading; update to reflect the new behaviour and contractThe function no longer mutates parents and its return type/meaning changed. Let’s align the docs.
-/// Determines whether the given parent node needs parens if used as the exponent in an exponentiation binary expression. +/// Determines whether the newly formed exponentiation expression should be parenthesised +/// in the current parent context of the original `Math.pow` call. +/// Returns `Some(true)` iff extra parentheses are required; otherwise `None` +/// (including when no parentheses are needed or when there is no relevant parent).
176-193
: Confirm Option contract and cover edge contexts with testsThe helper currently returns only
Some(true)
orNone
. That contract makes the call-site check correct, but please confirm this is intentional and stable.Also, worth verifying snapshots for contexts most sensitive to precedence/grammar:
class Foo extends Math.pow(A, B) {}
class extends Math.pow(A, B) {}
Math.pow(a, b).toString()
obj[Math.pow(a, b)]
Math.pow(a, b) in obj
typeof Math.pow(a, b)
Happy to draft focused tests if you want.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Format Rust and TOML files before committing (use
just f
/just format
).
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
🧠 Learnings (1)
📓 Common learnings
Learnt from: CR
PR: biomejs/biome#0
File: crates/biome_analyze/CONTRIBUTING.md:0-0
Timestamp: 2025-08-17T08:56:30.831Z
Learning: Applies to crates/biome_analyze/crates/biome_js_analyze/lib/src/lint/nursery/*.rs : For new JavaScript lint rules generated by `just new-js-lintrule`, implement the rule in the generated file under `biome_js_analyze/lib/src/lint/nursery/`
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (24)
- GitHub Check: Documentation
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Check Dependencies
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: Bench (biome_html_formatter)
- GitHub Check: Bench (biome_package)
- GitHub Check: Bench (biome_html_parser)
- GitHub Check: Bench (biome_configuration)
- GitHub Check: Bench (biome_module_graph)
- GitHub Check: Bench (biome_json_analyze)
- GitHub Check: Bench (biome_json_formatter)
- GitHub Check: Bench (biome_css_formatter)
- GitHub Check: Bench (biome_graphql_formatter)
- GitHub Check: Bench (biome_graphql_parser)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: Bench (biome_json_parser)
- GitHub Check: Bench (biome_css_analyze)
- GitHub Check: Bench (biome_css_parser)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Test Node.js API
- GitHub Check: autofix
CodSpeed Performance ReportMerging #7341 will not alter performanceComparing Summary
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs (1)
131-134
: Trailing trivia is dropped; leading trivia duplicated.
separator.leading_trivia()
is used twice. This risks losing comments after the comma and duplicating those before it. Swap the second call to usetrailing_trivia()
.- .append_trivia_pieces(chain_trivia_pieces( - separator.leading_trivia().pieces(), - separator.leading_trivia().pieces(), - ))?; + .append_trivia_pieces(chain_trivia_pieces( + separator.leading_trivia().pieces(), + separator.trailing_trivia().pieces(), + ))?;
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs (1)
173-191
: Docstring now misleads; it mentions a “parent node”.The helper returns whether the replacement needs parens in this context, not which parent to rewrite. Tighten the comment.
-/// Determines whether the given parent node needs parens if used as the exponent in an exponentiation binary expression. +/// Determines whether the newly created exponentiation expression needs parentheses +/// in the current context of this `Math.pow(...)` call.
📜 Review details
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
(2 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
**/*.{rs,toml}
📄 CodeRabbit inference engine (CONTRIBUTING.md)
Format Rust and TOML files before committing (use
just f
/just format
).
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
crates/biome_*_{syntax,parser,formatter,analyze,factory,semantic}/**
📄 CodeRabbit inference engine (CLAUDE.md)
Maintain the per-language crate structure: biome_{lang}_{syntax,parser,formatter,analyze,factory,semantic}
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
crates/biome_*/**
📄 CodeRabbit inference engine (CLAUDE.md)
Place core crates under /crates/biome_*/
Files:
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (25)
- GitHub Check: Lint project (depot-windows-2022)
- GitHub Check: End-to-end tests
- GitHub Check: Test (depot-windows-2022-16)
- GitHub Check: Test (depot-ubuntu-24.04-arm-16)
- GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
- GitHub Check: Check Dependencies
- GitHub Check: Documentation
- GitHub Check: Test Node.js API
- GitHub Check: Bench (biome_graphql_parser)
- GitHub Check: Bench (biome_js_analyze)
- GitHub Check: Bench (biome_package)
- GitHub Check: Bench (biome_module_graph)
- GitHub Check: Bench (biome_json_parser)
- GitHub Check: Bench (biome_css_formatter)
- GitHub Check: Bench (biome_css_analyze)
- GitHub Check: Bench (biome_configuration)
- GitHub Check: Bench (biome_json_analyze)
- GitHub Check: Bench (biome_js_formatter)
- GitHub Check: Bench (biome_html_formatter)
- GitHub Check: Bench (biome_json_formatter)
- GitHub Check: Bench (biome_html_parser)
- GitHub Check: Bench (biome_graphql_formatter)
- GitHub Check: Bench (biome_js_parser)
- GitHub Check: autofix
- GitHub Check: Bench (biome_css_parser)
🔇 Additional comments (1)
crates/biome_js_analyze/src/lint/style/use_exponentiation_operator.rs (1)
154-158
: Good call: parens are now applied locally to the new node.This avoids parent mutations and the batch-mutation last-write-wins footgun. Clean and robust.
|
@siketyan hi, It looks like the CI check has passed. However, the code has not been merged. I wonder if there is anything else that needs to be changed. |
@cqh963852 No, this PR is ready to merge. We usually wait a moment before merge so other maintainers may review the PR. |
Summary
Remove unnecessary node changes
Batch mutation currently uses the last write win, and parent modifications will be drop.
No parent modification is required here. Parentheses have been added to the child nodes.
Test Plan
Execute the unit tests in the repository to ensure that the snapshot has not been modified and the brackets are added normally
Docs