Skip to content

bugfix(formatter): keep parameter-list comment formatting idempotent#10208

Open
futurehua wants to merge 1 commit into
starkware-libs:mainfrom
futurehua:fix-formatter-parameter-comment
Open

bugfix(formatter): keep parameter-list comment formatting idempotent#10208
futurehua wants to merge 1 commit into
starkware-libs:mainfrom
futurehua:fix-formatter-parameter-comment

Conversation

@futurehua

Copy link
Copy Markdown

Summary

Fix formatter non-idempotence for line comments inside parameter lists.

Leading comments that remain on the current line now receive a separating space when neither an existing space nor a pending breakpoint already provides one. A regression fixture verifies both the expected output and formatter idempotence.

Fixes #10139.


Type of change

Please check one:

  • Bug fix (fixes incorrect behavior)
  • New feature
  • Performance improvement
  • Documentation change with concrete technical impact
  • Style, wording, formatting, or typo-only change

Why is this change needed?

Comments inside parameter lists are represented as leading trivia of the following token. When the associated breakpoint remains unbroken, the formatter previously emitted no separator before some of these comments.

As a result, the first formatting pass produced output such as:

fn foo(// before first param
a: u32, // between params
b: u32// before close paren
) {}

Reparsing that output classified the comments differently, so a second formatting pass inserted spaces. This violated the formatter's idempotence guarantee and caused editor, pre-commit, and CI formatting results to disagree.

Signed-off-by: futurehua <futurehua@outlook.com>
@cursor

cursor Bot commented Jul 17, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small, localized change in comment spacing within the formatter with a dedicated regression test; no runtime or security impact.

Overview
Fixes non-idempotent formatting when line comments sit inside parameter lists and stay on the same line as surrounding tokens (breakpoints not taken).

In push_comment, leading comments now get an explicit separating space when the line buffer has neither a trailing Space nor a pending break point with space_if_not_broken. Without that, the first format pass could emit fn foo(// … or b: u32// …, which reparses differently and causes a second pass to insert spaces.

Adds a parameter_list_comments golden test and expected output so the fixture and the existing idempotence check in format_and_compare_file lock in stable behavior.

Reviewed by Cursor Bugbot for commit 779c41b. Bugbot is set up for automated code reviews on this repo. Configure here.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: Formatter non-idempotent for comments in parameter lists

2 participants