[clang] [clang-format] Introduce "ReflowComments: IndentOnly" to re-indent comments without breaking internal structure (think Doxygen). (PR #96804)

Owen Pan via cfe-commits cfe-commits at lists.llvm.org
Wed Aug 14 18:20:29 PDT 2024


================
@@ -493,9 +493,36 @@ TEST_F(FormatTestComments, AlignsBlockComments) {
 
 TEST_F(FormatTestComments, CommentReflowingCanBeTurnedOff) {
   FormatStyle Style = getLLVMStyleWithColumns(20);
-  Style.ReflowComments = false;
-  verifyFormat("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style);
-  verifyFormat("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style);
+  Style.ReflowComments = FormatStyle::RCS_Never;
+  verifyNoChange("// aaaaaaaaa aaaaaaaaaa aaaaaaaaaa", Style);
+  verifyNoChange("/* aaaaaaaaa aaaaaaaaaa aaaaaaaaaa */", Style);
----------------
owenca wrote:

IIRC the main purpose of `messUp()` is to remove all syntactically optional newlines (and insert a single blank space if necessary). It also replaces consecutive whitespaces with a single one.

By convention we use `verifyFormat(x)` because it calls `messUp()`. Before I added `verifyNoChange()` and replaced hundreds of `verifyFormat(x, x)` with `verifyNoChange(x)`, the 2-argument `verifyFormat()` was the only way to avoid calling `messUp()`. Now we use `verifyFormat(output, input)` only when `input` and `output` differ, like the one you added on line 521 below.

So it would be better to use `verifyFormat()` here (consistency and no unrelated change) and below (consistency) even though `verifyNoChange()` would avoid an unnecessary call to `messUp()`.

https://github.com/llvm/llvm-project/pull/96804


More information about the cfe-commits mailing list