Skip to content
This repository was archived by the owner on Nov 1, 2021. It is now read-only.

Commit 7135967

Browse files
committed
[clang-format] Don't reflow comment lines starting with '@'.
Summary: This patch stops reflowing comment lines starting with '@', since they commonly have a special meaning. Reviewers: djasper Reviewed By: djasper Subscribers: cfe-commits, klimek Differential Revision: https://reviews.llvm.org/D29323 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@293617 91177308-0d34-0410-b5e6-96231b3b80d8
1 parent 23e4624 commit 7135967

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

lib/Format/BreakableToken.cpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,9 @@ static bool mayReflowContent(StringRef Content) {
304304
// Simple heuristic for what to reflow: content should contain at least two
305305
// characters and either the first or second character must be
306306
// non-punctuation.
307-
return Content.size() >= 2 && !Content.endswith("\\") &&
307+
return Content.size() >= 2 &&
308+
// Lines starting with '@' commonly have special meaning.
309+
!Content.startswith("@") && !Content.endswith("\\") &&
308310
// Note that this is UTF-8 safe, since if isPunctuation(Content[0]) is
309311
// true, then the first code point must be 1 byte long.
310312
(!isPunctuation(Content[0]) || !isPunctuation(Content[1]));

unittests/Format/FormatTest.cpp

+9
Original file line numberDiff line numberDiff line change
@@ -2244,6 +2244,15 @@ TEST_F(FormatTest, ReflowsComments) {
22442244
"// long long long long\n"
22452245
"// ... --- ...",
22462246
getLLVMStyleWithColumns(20)));
2247+
2248+
// Don't reflow lines starting with '@'.
2249+
EXPECT_EQ("// long long long\n"
2250+
"// long\n"
2251+
"// @param arg",
2252+
format("// long long long long\n"
2253+
"// @param arg",
2254+
getLLVMStyleWithColumns(20)));
2255+
22472256
// Reflow lines that have a non-punctuation character among their first 2
22482257
// characters.
22492258
EXPECT_EQ("// long long long\n"

0 commit comments

Comments
 (0)