Sitelet https://github.com/starkware-libs/cairo/pull/10045
Skip to content

bugfix(formatter): Made all single line comment prevent removing line-breaks. - #10045

Merged
orizi merged 1 commit into
mainfrom
orizi/06-07-bugfix_formatter_made_all_single_line_comment_prevent_removing_line-breaks
Jun 7, 2026
Merged

orizi merged 1 commit into
mainfrom
orizi/06-07-bugfix_formatter_made_all_single_line_comment_prevent_removing_line-breaks

Conversation

@orizi

@orizi orizi commented Jun 7, 2026 •

Copy link
Copy Markdown
Collaborator

Summary

Fixes the Cairo formatter incorrectly collapsing match arm bodies that contain doc comments (///) or inner comments (//!) into a single line, stripping the comment in the process. The fix updates is_statement_list_break_point_optional to check for TokenSingleLineComment, TokenSingleLineDocComment, and TokenSingleLineInnerComment syntax kinds directly, rather than walking through Trivia nodes and checking for SingleLineComment trivium variants (which did not cover doc/inner comment token kinds). A test case covering both /// and //! in match arm bodies is added.


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?

Match arm bodies containing doc comments (///) or inner comments (//!) were being incorrectly treated as candidates for collapsing to a single line. The previous check only recognized ast::Trivium::SingleLineComment, missing the doc and inner comment token kinds, so those comments were silently dropped when the formatter collapsed the block.


What was the behavior or documentation before?

A match arm like:

0 => {
    /// doc comment
    1
},

would be incorrectly formatted (the comment was dropped and the block collapsed).


What is the behavior or documentation after?

Match arm bodies containing /// or //! comments are preserved as multi-line blocks, keeping the comment intact:

0 => {
    /// doc comment
    1
},

Related issue or discussion (if any)

N/A


Additional context

The format_leading_comment doc comment was also updated to clarify that the formatter only merges continuation lines it broke off from over-long open lines, not lines the user wrote separately.

@reviewable-StarkWare

Copy link
Copy Markdown

This change is Reviewable

orizi commented Jun 7, 2026

Copy link
Copy Markdown
Collaborator Author

This stack of pull requests is managed by Graphite. Learn more about stacking.

@orizi
orizi marked this pull request as ready for review June 7, 2026 07:14
@cursor

cursor Bot commented Jun 7, 2026 •

Copy link
Copy Markdown

PR Summary

Low Risk
Formatter-only behavior change with a focused regression test; no runtime, auth, or data impact.

Overview
Fixes the Cairo formatter collapsing match arm (and similar) single-statement blocks when they contain /// or //! comments, which could drop or flatten those comments.

is_statement_list_break_point_optional now treats any descendant TokenSingleLineComment, TokenSingleLineDocComment, or TokenSingleLineInnerComment as blocking optional single-line collapse, instead of scanning trivia for plain SingleLineComment only. A formatter test locks in multi-line match arms with doc and inner comments. The format_leading_comment doc comment is clarified (user line breaks stay; only formatter-wrapped continuations merge).

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

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f6782dc31c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@orizi
orizi force-pushed the orizi/06-07-bugfix_formatter_made_all_single_line_comment_prevent_removing_line-breaks branch from f6782dc to 4670b30 Compare June 7, 2026 07:41

@TomerStarkware TomerStarkware left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

:lgtm:

@TomerStarkware reviewed 5 files and all commit messages, and made 1 comment.
Reviewable status: all files reviewed, 1 unresolved discussion (waiting on eytan-starkware and orizi).

@orizi orizi left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

@orizi resolved 1 discussion.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on eytan-starkware).

@orizi
orizi enabled auto-merge June 7, 2026 08:34
@orizi
orizi added this pull request to the merge queue Jun 7, 2026
Merged via the queue into main with commit 87584ac Jun 7, 2026
54 checks passed
@orizi
orizi deleted the orizi/06-07-bugfix_formatter_made_all_single_line_comment_prevent_removing_line-breaks branch June 7, 2026 11:25
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.

3 participants