I'd like this both for code and for comments.
Right now there's nothing that helps me when code gets really long. This is problematic with features like "implement interface" where an interface method might end up super long, making it tough to use in the IDE and in PRs.
After generation, i have to go in and manually wrap things. I'd like to have a preference (ideally project scoped) that says what column we try not to go past. Features like formatting/generation should attempt to respect this wrapping column when possible when they have items they can wrap. For example, method parameters would be a suitable wrapping entity.
Thanks!
For reference, I implemented this back in VS2005, but we ended up pulling it out. It ends up leading to another explosion of options for how to do the wrapping:
I'm not saying it's impossible, just that it's not nearly as simple as a single option for that the line length should be.
It would be nice if this could be implemented so as to support the max_line_length editorconfig parameter already supported by many editors.
So enforcing a _hard limit_ on line length is not actually possible in the language due to:
Here is a simple (and incomplete) proposal:
I feel these concerns have already been solved by prettier to a satisfactory degree
You can play around with it here https://prettier.io/playground/ (no it doesn't work with C#)
So enforcing a _hard limit_ on line length is not actually possible in the language due to:
- existing indentation rules: what if the user is 20 levels of indentation deep and therefore goes over the desired column width? Basically anywhere enforcing a column limit would violate another style rule we would need to decide who take precedence
- literals (especially string literals): while we could attempt to split string literals that exceed the column width it seems that this could potentially be re-writing the users code more than they intend
For me, there is no need to modify single tokens/literals. If a single token + indentation exceeds the column limit, I would expect the formatter to break after that token. The only exception would be semicolons, these should be kept on the same line as the last token.
I like your proposal a lot. Thank you!
@snebjorn prettier focuses on formatting in a single style for javascript. Whatever this formatting becomes it will need to interact with the many formatting options that already exist today for C#. I do not know how comparable to two situations are.
Small point:
If a single token + indentation exceeds the column limit, I would expect the formatter to break after that token.
That's not what i woudl expect. I would expect to break before teh column except in the case that breaking before would put the token on the same column as the line it was on (and thus would still be in the same problematic state). i.e. we should only cross the column as a last resort.
@snebjorn prettier focuses on formatting in a single style for javascript. Whatever this formatting becomes it will need to interact with the many formatting options that already exist today for C#. I do not know how comparable to two situations are.
Sorry I mistook this as the https://github.com/dotnet/format repo
@snebjorn no problem. Part of this discussion is trying to define what to goals are and how they differ from what other successful formatters do.
Meanwhile a JAVA plugin have appeared for prettier. JAVA and C# have pretty similar formatting concerns so perhaps it can be used as an inspiration :)
It's still early days, so it's not perfect.
Here's a playground https://shaolans.github.io/prettier-java-playground/
The link might change or go stale so here you can track changes https://github.com/jhipster/prettier-java/issues/193
Most helpful comment
It would be nice if this could be implemented so as to support the max_line_length editorconfig parameter already supported by many editors.