fix(lint): preserve ternary branch comments in noNegationElse#9630
Conversation
🦋 Changeset detectedLatest commit: 7a0ae0e 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 |
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
WalkthroughThe ternary ( Possibly related PRs
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)
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 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
crates/biome_js_analyze/src/lint/style/no_negation_else.rs (1)
109-113: Consider cloningcolon_tokenfor consistent trivia preservation.The
new_question_mark_tokenis created by cloning the original token (preserving its leading trivia), butnew_colon_tokenusesmake::token_decorated_with_space, which discards any original leading trivia on:. This could alter spacing in edge cases likea : b→b : a.For consistency:
✨ Suggested tweak
-let new_colon_token = make::token_decorated_with_space(T![:]) +let new_colon_token = colon_token + .clone() .with_trailing_trivia_pieces(question_mark_token.trailing_trivia().pieces());🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@crates/biome_js_analyze/src/lint/style/no_negation_else.rs` around lines 109 - 113, new_colon_token currently discards the original colon_token's leading trivia by using make::token_decorated_with_space; instead clone colon_token (similar to how new_question_mark_token clones question_mark_token) and set its leading/trailing trivia appropriately so the original spacing is preserved. Locate the variables question_mark_token, colon_token, new_question_mark_token and new_colon_token and replace the make::token_decorated_with_space construction with a colon_token.clone() (or equivalent clone method) then apply with_leading_trivia_pieces/with_trailing_trivia_pieces to mirror how new_question_mark_token is constructed.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@crates/biome_js_analyze/src/lint/style/no_negation_else.rs`:
- Around line 109-113: new_colon_token currently discards the original
colon_token's leading trivia by using make::token_decorated_with_space; instead
clone colon_token (similar to how new_question_mark_token clones
question_mark_token) and set its leading/trailing trivia appropriately so the
original spacing is preserved. Locate the variables question_mark_token,
colon_token, new_question_mark_token and new_colon_token and replace the
make::token_decorated_with_space construction with a colon_token.clone() (or
equivalent clone method) then apply
with_leading_trivia_pieces/with_trailing_trivia_pieces to mirror how
new_question_mark_token is constructed.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 3a3a153c-6b3f-4244-b36b-9cad6a753f03
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/style/noNegationElse/invalid.js.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (1)
crates/biome_js_analyze/src/lint/style/no_negation_else.rs
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@crates/biome_js_analyze/src/lint/style/no_negation_else.rs`:
- Around line 111-135: The code currently discards the alternate slot's suffix
returned by split_trailing_trivia, causing loss of spacing/newline after a moved
branch; capture both parts (e.g., let (alternate_trailing, alternate_suffix) =
split_trailing_trivia(...)) and when swapping attach the saved alternate_suffix
to the node that becomes the new alternate (use with_trailing_trivia_pieces for
the final mutation.replace_node_discard_trivia call instead of reusing
consequent_trailing), ensuring you still build new_consequent_trailing from
alternate_trailing and consequent_suffix as before; update usages of
alternate_trailing/alternate_suffix in replace_node_discard_trivia and
with_trailing_trivia_pieces to preserve the original suffix.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 61c87fea-dbd2-4e26-aecf-a06fa611ef9d
⛔ Files ignored due to path filters (1)
crates/biome_js_analyze/tests/specs/style/noNegationElse/invalid.js.snapis excluded by!**/*.snapand included by**
📒 Files selected for processing (2)
crates/biome_js_analyze/src/lint/style/no_negation_else.rscrates/biome_js_analyze/tests/specs/style/noNegationElse/invalid.js
✅ Files skipped from review due to trivial changes (1)
- crates/biome_js_analyze/tests/specs/style/noNegationElse/invalid.js
Merging this PR will not alter performance
Comparing Footnotes
|
dyc3
left a comment
There was a problem hiding this comment.
I can see that this fixes the issue, but I'm seeing a lot of cloning and .collect()/.to_vec(). These can cause performance problems, can we avoid them?
Summary
Testing
Closes #9629.