-
Notifications
You must be signed in to change notification settings - Fork 15.1k
clang-format reflow comments disable star: Fixes #58710 #167146
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
base: main
Are you sure you want to change the base?
Conversation
|
Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the LLVM GitHub User Guide. You can also ask questions in a comment on this PR, on the LLVM Discord or on the forums. |
|
@llvm/pr-subscribers-clang-format Author: bhanuponguru (bhanuponguru) ChangesCreated a new style "ReflowCommentsNoStar: true|false", to disable placing a star when blocked comments are split. Fixes #58710 Full diff: https://github.com/llvm/llvm-project/pull/167146.diff 7 Files Affected:
diff --git a/.clang-format b/.clang-format
index ecb44bfabd9aa..609dc68c8cd98 100644
--- a/.clang-format
+++ b/.clang-format
@@ -1,2 +1,5 @@
BasedOnStyle: LLVM
LineEnding: LF
+ColumnLimit: 80
+ReflowComments: true
+ReflowCommentsNoStar: true
\ No newline at end of file
diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index f246defc1fe81..2167544c0bd98 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4240,6 +4240,19 @@ struct FormatStyle {
/// \version 3.8
ReflowCommentsStyle ReflowComments;
+ /// If reflow comments is enabled, dont include * in the formatted block comment.
+ /// \code
+ /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+ /// // information
+ /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+ /// information */
+ /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
+ /// information and a misaligned second line */
+ /// \endcode
+
+ /// \version 22
+ bool ReflowCommentsNoStar;
+
/// Remove optional braces of control statements (``if``, ``else``, ``for``,
/// and ``while``) in C++ according to the LLVM coding style.
/// \warning
diff --git a/clang/lib/Format/BreakableToken.cpp b/clang/lib/Format/BreakableToken.cpp
index 994a427517ffc..677aa2026e272 100644
--- a/clang/lib/Format/BreakableToken.cpp
+++ b/clang/lib/Format/BreakableToken.cpp
@@ -506,6 +506,8 @@ BreakableBlockComment::BreakableBlockComment(
}
Decoration = "* ";
+ if (Style.ReflowCommentsNoStar)
+ Decoration = "";
if (Lines.size() == 1 && !FirstInLine) {
// Comments for which FirstInLine is false can start on arbitrary column,
// and available horizontal space can be too small to align consecutive
diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp
index dd14fcd72922f..f0bfa60fd76b2 100644
--- a/clang/lib/Format/Format.cpp
+++ b/clang/lib/Format/Format.cpp
@@ -1275,6 +1275,7 @@ template <> struct MappingTraits<FormatStyle> {
IO.mapOptional("RawStringFormats", Style.RawStringFormats);
IO.mapOptional("ReferenceAlignment", Style.ReferenceAlignment);
IO.mapOptional("ReflowComments", Style.ReflowComments);
+ IO.mapOptional("ReflowCommentsNoStar", Style.ReflowCommentsNoStar);
IO.mapOptional("RemoveBracesLLVM", Style.RemoveBracesLLVM);
IO.mapOptional("RemoveEmptyLinesInUnwrappedLines",
Style.RemoveEmptyLinesInUnwrappedLines);
diff --git a/clang/test/Format/ReflowCommentsNoStar.cpp b/clang/test/Format/ReflowCommentsNoStar.cpp
new file mode 100644
index 0000000000000..d1ce8506c818f
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStar.cpp
@@ -0,0 +1,2 @@
+// RUN: clang-format -style="{ColumnLimit: 80, ReflowComments: true, ReflowCommentsNoStar: true}" %S/ReflowCommentsNoStarInput.cpp > %t
+// RUN: diff %t %S/ReflowCommentsNoStarExpected.cpp
\ No newline at end of file
diff --git a/clang/test/Format/ReflowCommentsNoStarExpected.cpp b/clang/test/Format/ReflowCommentsNoStarExpected.cpp
new file mode 100644
index 0000000000000..35ba5e919f820
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStarExpected.cpp
@@ -0,0 +1,4 @@
+/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df
+ df df df df df df df fd f */
+
+void func() {}
diff --git a/clang/test/Format/ReflowCommentsNoStarInput.cpp b/clang/test/Format/ReflowCommentsNoStarInput.cpp
new file mode 100644
index 0000000000000..5ec0e32298337
--- /dev/null
+++ b/clang/test/Format/ReflowCommentsNoStarInput.cpp
@@ -0,0 +1,3 @@
+/* erfdfdfdfdfdfd fd fdfd fd fd fd fd fd fd fd fd fd fd fd fd fd fdf df df df df df df df df df df df fd f */
+
+void func() {}
|
You can test this locally with the following command:git-clang-format --diff origin/main HEAD --extensions h,cpp -- clang/test/Format/ReflowCommentsNoStar.cpp clang/test/Format/ReflowCommentsNoStarExpected.cpp clang/test/Format/ReflowCommentsNoStarInput.cpp clang/include/clang/Format/Format.h clang/lib/Format/BreakableToken.cpp clang/lib/Format/Format.cpp --diff_from_common_commit
View the diff from clang-format here.diff --git a/clang/include/clang/Format/Format.h b/clang/include/clang/Format/Format.h
index 1c3050ec9..4de1a9f40 100644
--- a/clang/include/clang/Format/Format.h
+++ b/clang/include/clang/Format/Format.h
@@ -4250,15 +4250,19 @@ struct FormatStyle {
/// \version 3.8
ReflowCommentsStyle ReflowComments;
- /// If reflow comments is enabled, dont include * in the formatted block comment.
- /// \code
- /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
- /// // information
- /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
- /// information */
- /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty of
- /// information and a misaligned second line */
- /// \endcode
+ /// If reflow comments is enabled, dont include * in the formatted block
+ /// comment.
+ /// \code
+ /// // veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with plenty
+ /// of
+ /// // information
+ /// /* second veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
+ /// plenty of
+ /// information */
+ /// /* third veryVeryVeryVeryVeryVeryVeryVeryVeryVeryVeryLongComment with
+ /// plenty of
+ /// information and a misaligned second line */
+ /// \endcode
/// \version 22
bool ReflowCommentsNoStar;
|
Created a new style "ReflowCommentsNoStar: true|false", to disable placing a star when blocked comments are split.
Fixes #58710