From d64fb779017f1c0bb1984fa831b71ee358ce9d94 Mon Sep 17 00:00:00 2001 From: Wim Looman Date: Fri, 9 Feb 2024 12:22:43 +0100 Subject: [PATCH] Include examples of all `wrap_comments` settings and header handling --- Configurations.md | 78 +++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 69 insertions(+), 9 deletions(-) diff --git a/Configurations.md b/Configurations.md index ffc0dddc95c..2c7f1dc44dc 100644 --- a/Configurations.md +++ b/Configurations.md @@ -3096,34 +3096,88 @@ Note that no wrapping will happen if: 1. The comment is the start of a markdown header doc comment 2. An URL was found in the comment -- **Default value**: `"off"` -- **Possible values**: `"doc"`, `"normal"`, `"all"` (alias `true`), `"off"` (alias `false`) +- **Default value**: `"Off"` +- **Possible values**: `"Off"` (alias `false`), `"All"` (alias `true`), `"Doc"`, `"Normal"` - **Stable**: No (tracking issue: [#3347](https://github.com/rust-lang/rustfmt/issues/3347)) -#### `"off"` (default): +#### `"Off"` (default): + +Can also be specified as `wrap_comments = false`. ```rust -// 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. +// # This comment looks like a very long header (it starts with a '#'). Had it been a doc comment it would not have been wrapped, because wrapping a markdown header breaks it. But because it is a normal comment, it will be. // 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. // Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. + +/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. +/// +/// 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. +/// +/// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. struct Foo {} ``` -#### `"all"`: +#### `"All"`: + +Can also be specified as `wrap_comments = true`. ```rust +// # This comment looks like a very long header (it starts +// with a '#'). Had it been a doc comment it would not have +// been wrapped, because wrapping a markdown header breaks +// it. But because it is a normal comment, it will be. + // 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. +// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. + +/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. +/// +/// 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. +/// +/// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. +struct Foo {} +``` + +#### `"Doc"`: + +```rust +// # This comment looks like a very long header (it starts with a '#'). Had it been a doc comment it would not have been wrapped, because wrapping a markdown header breaks it. But because it is a normal comment, it will be. + +// 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. + +// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. + +/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. +/// +/// 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. +/// +/// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. +struct Foo {} +``` + +#### `"Normal"`: + +```rust +// # This comment looks like a very long header (it starts +// with a '#'). Had it been a doc comment it would not have +// been wrapped, because wrapping a markdown header breaks +// it. But because it is a normal comment, it will be. + // 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 @@ -3131,6 +3185,12 @@ struct Foo {} // commodo consequat. // Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. + +/// # This doc comment is a very long header (it starts with a '#'). Had it not been a header it would have been wrapped. But because it is a header, it will not be. That is because wrapping a markdown header breaks it. +/// +/// 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. +/// +/// Information on the lorem ipsum can be found at the following url: https://en.wikipedia.org/wiki/Lorem_ipsum. Its text is: 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. struct Foo {} ```