Skip to content

Conversation

0xrusowsky
Copy link
Contributor

Motivation

closes #12076

Solution

don't normalize single-line non-doc block comments

PR Checklist

  • Added Tests
  • Added Documentation
  • Breaking changes

Comment on lines 7 to 9
/*´:°•.°+.*•´.*:˚.°*.˚•´.°:°•.°•.*•´.*:˚.°*.˚•´.°:°•.°+.*•´.*:*/
/* FUNCTIONS */
/*.•°:°.´+˚.*°.˚:*.´•*.+°.•°:´*.´•*.•°.•°:°.´:•˚°.*°.˚:*.´+°.•*/
Copy link
Contributor Author

@0xrusowsky 0xrusowsky Oct 13, 2025

Choose a reason for hiding this comment

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

when wrapping comments we need to split the comment content into words, and separate them with soft breaking spaces.

if a user has comment wrapping enabled and they want to do custom art with their comments, they may have to disable the fmt for that block.

imo this is totally fine, as custom style conflicts with comment wrapping

Copy link
Member

Choose a reason for hiding this comment

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

does this mean that you can't have more than 1 consecutive space inside of a comment when wrapping is enabled? we can ignore this here but that doesn't sound right

Copy link
Contributor Author

Choose a reason for hiding this comment

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

since when wrapping comments we defer the breaking logic to the PP, and we wouldn't know when it would break, the current approach is to split cmnt content into words, stripping whitespaces and exchanging them for a single PP breaking space:

let mut words = content.split_whitespace().peekable();

i can change the approach and go char by char though if we are not happy with this approach

Copy link
Contributor Author

@0xrusowsky 0xrusowsky Oct 13, 2025

Choose a reason for hiding this comment

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

addressed in 6983489 (#12078)

@0xrusowsky 0xrusowsky enabled auto-merge (squash) October 13, 2025 12:25
}
let prefix = post_break_prefix(prefix, rest.len());
(prefix, rest)
} else if line.starts_with("/*") && !line.starts_with("/* ") {
Copy link
Collaborator

Choose a reason for hiding this comment

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

cannot this happen on comments starting with // or /// ?

Copy link
Contributor Author

@0xrusowsky 0xrusowsky Oct 13, 2025

Choose a reason for hiding this comment

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

afaik doc comments must have the space afterwards, otherwise they are not identified as doc comments.

personally i felt like //* was weird, but i can modify the patch to allow it too. Should i do it @grandizzy? addressed in 6983489 (#12078)

@0xrusowsky 0xrusowsky disabled auto-merge October 13, 2025 13:50
@0xrusowsky 0xrusowsky requested a review from grandizzy October 13, 2025 15:14
let content = &line[prefix.len()..];
let content = if is_doc {
// Doc comments preserve leading whitespaces (right after the prefix) as nbps.
let ws_len = content.chars().take_while(|&c| c.is_whitespace()).count();
Copy link
Member

Choose a reason for hiding this comment

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

this is char count instead of byte count

@0xrusowsky 0xrusowsky merged commit f111fb1 into master Oct 14, 2025
16 checks passed
@0xrusowsky 0xrusowsky deleted the rusowsky/12076 branch October 14, 2025 13:07
@github-project-automation github-project-automation bot moved this to Done in Foundry Oct 14, 2025
grandizzy pushed a commit to grandizzy/foundry that referenced this pull request Oct 14, 2025
…#12078)

* fix: don't normalize single-line non-doc block cmnts

* fix: preserve consecutive whitespaces

* fix: use byte length instead of char count
grandizzy added a commit that referenced this pull request Oct 14, 2025
* fix(fmt): ensure commasep breaks with final trailing cmnt (#12031)

* fix(fmt): refine logic over comments between uninformed commasep (#12055)

* fix(anvil): set envelope for non deposit tx in debug tracers (#12080)

* chore: bump v1.4.1 (#12083)

chore: bumpt v1.4.1

* fix(fmt): don't normalize single-line non-doc block cmnts (#12078)

* fix: don't normalize single-line non-doc block cmnts

* fix: preserve consecutive whitespaces

* fix: use byte length instead of char count

---------

Co-authored-by: 0xrusowsky <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

bug(fmt): bad block comment formatting and formatter rules ignored

3 participants