[PATCH] D90908: [clang-format] do not break before { in JS comments
Krasimir Georgiev via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Nov 6 01:35:38 PST 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG2dbcbd357d1d: [clang-format] do not break before { in JS comments (authored by krasimir).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D90908/new/
https://reviews.llvm.org/D90908
Files:
clang/lib/Format/BreakableToken.cpp
clang/unittests/Format/FormatTestJS.cpp
Index: clang/unittests/Format/FormatTestJS.cpp
===================================================================
--- clang/unittests/Format/FormatTestJS.cpp
+++ clang/unittests/Format/FormatTestJS.cpp
@@ -2184,6 +2184,16 @@
" * @lala {lala {lalala\n"
" */\n",
getGoogleJSStyleWithColumns(20));
+ // cases where '{' is around the column limit
+ for (int ColumnLimit = 6; ColumnLimit < 13; ++ColumnLimit) {
+ verifyFormat("/**\n"
+ " * @param {type}\n"
+ " */",
+ "/**\n"
+ " * @param {type}\n"
+ " */",
+ getGoogleJSStyleWithColumns(ColumnLimit));
+ }
verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n"
" */",
Index: clang/lib/Format/BreakableToken.cpp
===================================================================
--- clang/lib/Format/BreakableToken.cpp
+++ clang/lib/Format/BreakableToken.cpp
@@ -86,6 +86,18 @@
MaxSplitBytes += BytesInChar;
}
+ // In JavaScript, some @tags can be followed by {, and machinery that parses
+ // these comments will fail to understand the comment if followed by a line
+ // break. So avoid ever breaking before a {.
+ if (Style.Language == FormatStyle::LK_JavaScript) {
+ StringRef::size_type SpaceOffset =
+ Text.find_first_of(Blanks, MaxSplitBytes);
+ if (SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
+ Text[SpaceOffset + 1] == '{') {
+ MaxSplitBytes = SpaceOffset + 1;
+ }
+ }
+
StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
static const auto kNumberedListRegexp = llvm::Regex("^[1-9][0-9]?\\.");
@@ -94,9 +106,7 @@
// as a numbered list, which would prevent re-flowing in subsequent passes.
if (kNumberedListRegexp.match(Text.substr(SpaceOffset).ltrim(Blanks)))
SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
- // In JavaScript, some @tags can be followed by {, and machinery that parses
- // these comments will fail to understand the comment if followed by a line
- // break. So avoid ever breaking before a {.
+ // Avoid ever breaking before a { in JavaScript.
else if (Style.Language == FormatStyle::LK_JavaScript &&
SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90908.303369.patch
Type: text/x-patch
Size: 2450 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201106/df6f1aa4/attachment.bin>
More information about the cfe-commits
mailing list