-
Notifications
You must be signed in to change notification settings - Fork 898
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
for consistency, stop lines from automatically collapsing even if such a joined line would not exceed max_width #5765
Comments
@effinsky Thanks for reaching out. Not sure what version of rustfmt you're using, but you can try to set Also want to note that something similar was brought up in #5190. Hope that helps, but I'm going to close this as we don't usually want the existence or lack of a comma in the input to dictate how we layout lists. |
Thank you for reaching out, and taking the time to articulate your suggestion so thoroughly! To add on to what Yacin said, this is not something we'd be willing to incorporate for a few reasons, the main one being that this would be a source of idempotence issues due to the presence of existing features that manipulate trailing commas. Your best bet to get your preferred formatting style is likely going to be to utilize a combination of the short_array_element_width_threshold and line comments where necessary to force a vertical layout |
Thanks, and fyi |
how about adding a setting to preserve shorter lines even if more than a single statement or expression would otherwise fit on a single line? so no trailing comma manipulation, but a general setting or Preserve? or something like "max_line_length_within_limit" with a true, false, so that when I say false to that, I'll get to keep my shorter lines for alignment, readability etc? I mean quite clearly at present we do lose some readability sometimes where we have subsequent analogous lines formatted differently. I'd be cool to be able to have that consistent formatting line to line, as in the examples above. you can use fmt skip on those, yes, but that way you lose all formatting and all benefits of the tool. I'd rather not have these skips sprinkled over the code since that reduces readability too. |
For consistent formatting across multiple like statements, declarations, assignments etc, make it possible for separate lines to not unfold into a single line even if that line would be < max_width. This is inspired by own felt need/preference, the black Python formatter for Python, and the Zig formatter.
In both
black
for Python andzigfmt
if you put a trailing comma on a list of params, for instance, that'll be a cue for the formatter to not collapse multiple lines into a single line even if they could be since, say, they comprise a single statement and are below max line length.Wish we could have a thing like that in
rustfmt
. First and foremost this would help readability in cases where you have a series of statements where one does not fit a single line and therefore will be broken down into multiple lines, but the rest do and therefore will not be broken down. For ease of visual pattern recognition I'd like to allow for breaking them all down into the same formatting scheme across multiple lines.Currently
rustfmt
formats this and like examples:I'd like to force line breaking into this much nicer formatting without sprinkling fmt skip and such all over the place:
In Python's black... Unformatted:
If I run black, it behaves similar to how
rustfmt
would, producing:But if I add trailing commas manually here and here:
Then I get the nice result of:
What do you think?
The text was updated successfully, but these errors were encountered: