-
Notifications
You must be signed in to change notification settings - Fork 56
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
Customization: option to prevent joining lines #40
Comments
This is not really possible the way Rustfmt is written. It doesn't really take the source text into account, it parses the source, and then reformats the AST from scratch. An early version of Rustfmt tried a 'modifying' rather than re-writing approach, but it didn't work out very well - as soon as you start correcting in even minor ways, you end up needing to shuffle around lots of surrounding code and then it is really difficult to know what preserving is meant to do. So, I think it is possible to do this, but it would be a rewrite of Rustfmt and much more difficult to do well than the current approach, |
Closing since this is not really possible in Rustfmt, and because this would more likely be an option in Rustfmt rather than part of the style specification. |
Are you sure? It would have to mean the style would not enforce/specify that lines should be joined in such situations. |
Yes. We try do something like this for Strings and comments, and it is horrible. |
I'd like to make a case that one of the customization options for
rustfmt
should be an option to be conservative about joining lines.Recently in another issue @nikomatsakis commented that
rustfmt
turns this code:into this:
which wasn't desirable. This was in the context of the #8 discussion, however the issue of joining lines is a more general issue that goes beyond what indentation style one chooses.
Let me me give a motivating example. Suppose you have this code and a column limit of 100:
If you invoke the formatter and it forcibly joins lines when it can, it can join
function_one
into:because
function_one
signature can still fit in the column limit. However, iffunction_one
andfunction_two
are conceptually related to one another, you might want for them to maintain a similar line-break structure, because they will look similar and be easier to read (IMO), due to being more uniform.Similarly, but suppose instead the column limit is 80. You could have this code to start with:
Running the formatter could join
function_one
into:because that would fit the column limit. But again you might want to preserve line-breaks in order to be more consistent with how the other related function is formatted.
It also makes it easier to add/remove parameters to either function, since you just need to add/remove the line with the parameter. Editing whole lines is usually easier/quicker than segments of a line, in most editors.
Also, it's more "stable" if lines are not joined: renaming a parameter name (or the type) to something shorter does not risk joining lines. Whereas otherwise it might, if the formatter always joins lines.
I would find annoying if the whole signature gets reformatted and joined, just because I rename
function_two
'ssome_parameter
tosome_param
or so. Again, I admit this can be subjective. If you care about not wasting vertical space (I don't) you might prefer the opposite.The text was updated successfully, but these errors were encountered: