The formatter only leaves one space before a comment. I find this visually hard to parse, for example:
mass = Tons(50) # this is the mass of the thing
mass_in_kilograms =
match mass {
Kilos(kilos) => kilos # just plain kilos
Tons(tons) => tons * 1000 # oh wow we have tons now
Kilotons(kilotons) => kilotons * 1_000_000 # and kilotons, that's nuts
}
Contrast that with double-space:
mass = Tons(50) # this is the mass of the thing
mass_in_kilograms =
match mass {
Kilos(kilos) => kilos # just plain kilos
Tons(tons) => tons * 1000 # oh wow we have tons now
Kilotons(kilotons) => kilotons * 1_000_000 # and kilotons, that's nuts
}
For what it's worth, several other languages use double spaces before comments after code:
Just submitted PR #11262 to have two spaces (instead of one) before inline comments.
I dunno about this one...I don't think any other formatters do that, do they?
I understand the argument, but I can very easily anticipate complaints in the other direction :smile:
Yes, a bunch of formatters do that:
SpacesBeforeTrailingComments: 2)sp_num_before_tr_emb_cmt = 2)Edit: looks like the default is 1 except for Python and Meson. It's interesting that style guides recommend 2 spaces but the formatters don't do it by default.
And a bunch of style guides recommend it (see the list I posted above)
I guess we could make it configurable, but my understanding is that roc fmt is opinionated, so we have to choose. I find it much cleaner, visually, but it might just be a matter of taste. Perhaps we could have a little vote just to see if most people agree that double-space is easier to read?
Here's Python's style guide on (at least) two spaces for inline comments:
![]()
Interestingly, they also recommend using inline comments sparingly.
/poll How many spaces do you prefer before inline comments?
One space exactly
Two spaces exactly
At least one space
At least two spaces
Other (comment)
Wouldn't a tab \t be more correct here?
One idea to help with this that Joshua was doing back with the development of the formatter ...
Download heaps of Roc files from known up to date projects using a python script.
Implement the new formatter rule, run it over all the docs and assess the impact.
I think he name his script (it grew a lot of capabilites and did lot of things) Roc Osprey or something... after a seagoing bird that can cover great distances :grinning_face_with_smiling_eyes:
Last updated: Sep 24 2026 at 15:59 UTC