Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@arendjr
Copy link
Contributor

@arendjr arendjr commented Nov 19, 2025

Summary

Fixed #7999: Correctly place await after leading comment in auto-fix action from noFloatingPromises rule.

Test Plan

Test case included.

Docs

N/A

@arendjr arendjr requested a review from Conaclos November 19, 2025 15:39
@changeset-bot
Copy link

changeset-bot bot commented Nov 19, 2025

🦋 Changeset detected

Latest commit: 93c4193

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 13 packages
Name Type
@biomejs/biome Patch
@biomejs/cli-win32-x64 Patch
@biomejs/cli-win32-arm64 Patch
@biomejs/cli-darwin-x64 Patch
@biomejs/cli-darwin-arm64 Patch
@biomejs/cli-linux-x64 Patch
@biomejs/cli-linux-arm64 Patch
@biomejs/cli-linux-x64-musl Patch
@biomejs/cli-linux-arm64-musl Patch
@biomejs/wasm-web Patch
@biomejs/wasm-bundler Patch
@biomejs/wasm-nodejs Patch
@biomejs/backend-jsonrpc Patch

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

@github-actions github-actions bot added A-Core Area: core A-Linter Area: linter L-JavaScript Language: JavaScript and super languages labels Nov 19, 2025
@arendjr arendjr force-pushed the fix-no-floating-promises-action branch from d0fc7cb to 93c4193 Compare November 19, 2025 15:44
@codspeed-hq
Copy link

codspeed-hq bot commented Nov 19, 2025

CodSpeed Performance Report

Merging #8169 will not alter performance

Comparing arendjr:fix-no-floating-promises-action (93c4193) with main (7d963f3)

Summary

✅ 58 untouched
⏩ 95 skipped1

Footnotes

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

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 19, 2025

Walkthrough

This pull request fixes a bug in the noFloatingPromises rule's auto-fix action where the await operator was incorrectly positioned when leading comments were present. The fix introduces two new trivia-handling methods: replace_node_transfer_trivia() on BatchMutation to preserve and combine trivia during node replacement, and trim_comments_and_trivia() on the AstNode trait to strip leading and trailing trivia. The rule implementation now uses these utilities to properly handle comments before wrapping expressions in await. A test case for issue #7999 validates the corrected behaviour.

Suggested reviewers

  • ematipico
  • dyc3

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and concisely describes the main fix: correctly placing await after comments in the noFloatingPromises rule auto-fix.
Description check ✅ Passed The description is directly related to the changeset, explaining the fix for issue #7999 and mentioning the included test case.
Linked Issues check ✅ Passed The PR fully addresses issue #7999 by implementing the expected fix: await is now correctly placed after leading comments via the new trim_comments_and_trivia method and replace_node_transfer_trivia API.
Out of Scope Changes check ✅ Passed All changes are directly scoped to fixing the issue: the rule logic fix, test case, necessary AST utilities, and batch mutation API are all required for the solution.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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/nursery/no_floating_promises.rs (1)

290-305: Await + trivia handling for UnhandledPromise looks correct

Using trim_comments_and_trivia() for the wrapped expression plus replace_node_transfer_trivia for the replacement should keep leading comments/whitespace on the whole statement while ensuring the await is inserted immediately before the expression, not the comment. That matches the intended behaviour for issue #7999.

If you find you need the same treatment elsewhere, it might be worth considering replace_node_transfer_trivia in other rule actions for consistency, but it’s not required for this fix.

crates/biome_rowan/src/ast/mod.rs (1)

279-287: Clarify trim_comments_and_trivia semantics in the doc comment

The implementation strips leading/trailing trivia on the node’s boundary (first/last tokens), which is exactly what the rule needs. The phrase “all trivia” could be read more broadly though — maybe reword to something like “all leading and trailing trivia (including comments) from this node” and briefly contrast it with trim_trivia to make the intent unmistakable to future callers.

crates/biome_rowan/src/ast/batch.rs (1)

224-253: replace_node_transfer_trivia behaviour looks good; consider tightening API/usage

The trivia merging logic (prev + next leading, prev + next trailing) is a sensible analogue to replace_token_transfer_trivia, and suits the noFloatingPromises use-case.

The only nit is the Option<()> return: in the current caller it’s ignored, so a theoretical None would silently yield an “empty” mutation. Either treating the missing-token case as unreachable and returning () here, or having call sites propagate the Option with ?, would make the failure mode more explicit.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 575129a and d0fc7cb.

📒 Files selected for processing (6)
  • .changeset/balanced-bananas-balloon.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js.snap.new (1 hunks)
  • crates/biome_rowan/src/ast/batch.rs (1 hunks)
  • crates/biome_rowan/src/ast/mod.rs (1 hunks)
🧰 Additional context used
🧠 Learnings (1)
📚 Learning: 2025-08-05T14:43:29.581Z
Learnt from: dyc3
Repo: biomejs/biome PR: 7081
File: packages/@biomejs/biome/configuration_schema.json:7765-7781
Timestamp: 2025-08-05T14:43:29.581Z
Learning: The file `packages/biomejs/biome/configuration_schema.json` is auto-generated and should not be manually edited or reviewed for schema issues; any changes should be made at the code generation source.

Applied to files:

  • .changeset/balanced-bananas-balloon.md
🧬 Code graph analysis (1)
crates/biome_rowan/src/ast/batch.rs (1)
crates/biome_rowan/src/syntax/token.rs (1)
  • trailing_trivia (492-494)
⏰ 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). (27)
  • GitHub Check: Test Node.js API
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Documentation
  • GitHub Check: End-to-end tests
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Validate rules documentation
  • GitHub Check: Bench (biome_js_parser)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: lint
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Parser conformance
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_parser)
🔇 Additional comments (3)
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js (1)

6-10: Nice focused regression test

The issue7999 case cleanly captures the “comment + floating promise in async function” scenario, and lines up with the new snapshot. Good addition.

crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js.snap.new (1)

1-75: Snapshot accurately reflects the new behaviour

The diagnostics and the unsafe fix snippet look spot on: only the async-function call is marked fixable, and the suggested edit inserts await after the leading comment with indentation preserved.

.changeset/balanced-bananas-balloon.md (1)

1-5: Clear, user-facing summary

Nice concise changeset: it names the rule, the behaviour change, and links the original issue. Nothing to tweak here.

Copy link
Contributor

@coderabbitai coderabbitai bot left a 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 (1)
crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js (1)

6-10: LGTM! Test case correctly exercises the fix.

The test case properly validates the issue where a leading comment preceded the floating promise. The auto-fix should now place await after the comment rather than before it.

Consider adding test cases for edge cases such as block comments (/* comment */) or multiple leading comments, though this focused test is sufficient for the reported issue.

📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between d0fc7cb and 93c4193.

⛔ Files ignored due to path filters (1)
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js.snap is excluded by !**/*.snap and included by **
📒 Files selected for processing (5)
  • .changeset/balanced-bananas-balloon.md (1 hunks)
  • crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs (1 hunks)
  • crates/biome_js_analyze/tests/specs/nursery/noFloatingPromises/invalid.js (1 hunks)
  • crates/biome_rowan/src/ast/batch.rs (1 hunks)
  • crates/biome_rowan/src/ast/mod.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (4)
  • crates/biome_js_analyze/src/lint/nursery/no_floating_promises.rs
  • .changeset/balanced-bananas-balloon.md
  • crates/biome_rowan/src/ast/mod.rs
  • crates/biome_rowan/src/ast/batch.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). (24)
  • GitHub Check: Bench (biome_json_analyze)
  • GitHub Check: Bench (biome_json_parser)
  • GitHub Check: Bench (biome_json_formatter)
  • GitHub Check: Test Node.js API
  • GitHub Check: Test (depot-windows-2022-16)
  • GitHub Check: Documentation
  • GitHub Check: Test (depot-ubuntu-24.04-arm-16)
  • GitHub Check: Lint project (depot-windows-2022)
  • GitHub Check: Check Dependencies
  • GitHub Check: Bench (biome_tailwind_parser)
  • GitHub Check: Bench (biome_css_formatter)
  • GitHub Check: Bench (biome_css_analyze)
  • GitHub Check: Bench (biome_css_parser)
  • GitHub Check: Bench (biome_configuration)
  • GitHub Check: autofix
  • GitHub Check: Bench (biome_graphql_formatter)
  • GitHub Check: Bench (biome_graphql_parser)
  • GitHub Check: Bench (biome_module_graph)
  • GitHub Check: Validate rules documentation
  • GitHub Check: Bench (biome_package)
  • GitHub Check: Parser conformance
  • GitHub Check: Bench (biome_js_analyze)
  • GitHub Check: Bench (biome_js_formatter)
  • GitHub Check: Bench (biome_js_parser)

@arendjr arendjr added this pull request to the merge queue Nov 19, 2025
Merged via the queue into biomejs:main with commit 7fdcec8 Nov 19, 2025
31 checks passed
@arendjr arendjr deleted the fix-no-floating-promises-action branch November 19, 2025 18:35
@github-actions github-actions bot mentioned this pull request Nov 19, 2025
ryan-m-walker pushed a commit to ryan-m-walker/biome that referenced this pull request Nov 23, 2025
l0ngvh pushed a commit to l0ngvh/biome that referenced this pull request Dec 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-Core Area: core A-Linter Area: linter L-JavaScript Language: JavaScript and super languages

Projects

None yet

Development

Successfully merging this pull request may close these issues.

💅 bug in code action for noFloatingPromises rule

2 participants