-
Notifications
You must be signed in to change notification settings - Fork 888
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
[unstable option] comment_width #3349
Comments
Not sure if this is the right place to add this comment or not; feel free to tell me to go somewhere else. I was surprised to find out that the default value for So before Do text editors display/enforce different widths for comments vs code? I use TextMate, and it just has one wrap column setting. Examples: What looks "good" to me: // This line of code is just about width 100
fn evaluate_something_test(something: &Something, number: usize) -> Result<BTreeMap, CustomError> {
// This comment is wrapped to 100. Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
// do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
// nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute...
unimplemented!();
// This is what I would expect. irure dolor in reprehenderit in voluptate velit esse cillum
// dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
// culpa qui officia deserunt mollit anim id est laborum.
} What looks "strange" to me: // This line of code is just about width 100
fn evaluate_something_test(something: &Something, number: usize) -> Result<BTreeMap, CustomError> {
// This comment is wrapped to 80. Lorem ipsum dolor sit amet, consectetur
// adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore
// magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation
// ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute...
unimplemented!();
// This looks strange to me. irure dolor in reprehenderit in voluptate
// velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint
// occaecat cupidatat non proident, sunt in culpa qui officia deserunt
// mollit anim id est laborum.
} |
These options are unstable and depend on the following PR's: rust-lang/rustfmt#3347 rust-lang/rustfmt#3349
Aims to close #1594. These options are unstable and depend on the following PR's: [wrap_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#wrap_comments): rust-lang/rustfmt#3347 [comment_width](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#comment_width): rust-lang/rustfmt#3349 [normalize_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#normalize_comments): rust-lang/rustfmt#3350 @alice-i-cecile do you think this will solve the issue? When enabled, running the formatter locally should take the configurations into account to format comments. `--check` runs should also be considering them. This should be testable on the `nightly` toolchain. ~I didn't delve into normalizing `//` vs `/* */` though, should I take a look into that too? [normalize_comments](https://rust-lang.github.io/rustfmt/?version=v1.4.36&search=#normalize_comments) seems to be the solution for that but it's also unstable (tracking issue: rust-lang/rustfmt#3350). I can also add this configuration (commented out, of course) if it's desirable.~ Added `normalize_comments` option.
It was a bit weird that the `comment_width` was configured to be _longer_ than the `max_width` which sets the maximum width of each line. I choose to explictly set `max_width` to its default value of 100 for clarity. The reason why we don't see any other changes to the diff should be obvious: setting `comment_width` to more than `max_width` was useless! Inspired by: rust-lang/rustfmt#3349 (comment).
It was a bit weird that the `comment_width` was configured to be _longer_ than the `max_width` which sets the maximum width of each line. I choose to explictly set `max_width` to its default value of 100 for clarity. The reason why we don't see any other changes to the diff should be obvious: setting `comment_width` to more than `max_width` was useless! Inspired by: rust-lang/rustfmt#3349 (comment).
2572: Set `rustfmt` max comment and line width to 100 r=luckysori a=luckysori It was a bit weird that the `comment_width` was configured to be _longer_ than the `max_width` which sets the maximum width of each line. I choose to explicitly set `max_width` to its default value of 100 for clarity. The reason why we don't see any other changes to the diff should be obvious: setting `comment_width` to more than `max_width` was useless! Inspired by: rust-lang/rustfmt#3349 (comment). Co-authored-by: Lucas Soriano del Pino <[email protected]>
will add explicitly, and more verbosely, that I'd prefer to see the default for this option be the same value as max_width as well. AFACIT the default value of 80 for this was established way back in 2015 in a rather ad-hoc manner during the earliest days of rustfmt development, and it seems to have continued on being the default ever since without any explicit discussion and reasoning around why it is less than max_width (at least none that I could find, though happy to be proven wrong). |
Would it be possible to default to whatever I'm thinking that in most cases, anybody who changes |
I remember looking up what the problem with stabilizing this was. But I can't remember where to find it. Can someone point me in the right direction please. Since I'm commenting I'll just add a +1 for the single setting to |
Yes, there's a number of width related options implemented this way
More generally, see #5365 #5367 In this particular case, there's a salient, unresolved question of what the default value should be. It's a question on the Style Team's radar as well, but full disclosure, I do not anticipate this is an option that'll be stabilized in the immediate future (i.e. I'd be surprised if this is done by year end, but suspect it will be by the time the 2024 edition drops) |
Thank you appreciate the links. I wasn't sure where to look for them. |
What's the current default value when I run |
The current default is 80 However, rustfmt doesn't format comments on stable, so this option isn't operative on stable The description of the option is:
But
I understand where you're coming from with this argument, but the default value for a config option (regardless of whether the option is a boolean, numeric, etc. type) is a critical factor and part of the long established process for stabilizing options. Whether there could or should be changes to that process is fair topic for discussion, but so long as that is the process then that's what will be followed for all options, including this one. (edit: clarified answer as I'd originally missed the "on stable" suffix of the question) |
Tracking issue for unstable option: comment_width
The text was updated successfully, but these errors were encountered: