[PATCH] D50249: clang-format: [JS] don't break comments before any '{'
Martin Probst via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 3 06:59:15 PDT 2018
This revision was automatically updated to reflect the committed changes.
Closed by commit rC338890: clang-format: [JS] don't break comments before any '{' (authored by mprobst, committed by ).
Changed prior to commit:
https://reviews.llvm.org/D50249?vs=158993&id=159001#toc
Repository:
rC Clang
https://reviews.llvm.org/D50249
Files:
lib/Format/BreakableToken.cpp
unittests/Format/FormatTestJS.cpp
Index: lib/Format/BreakableToken.cpp
===================================================================
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -90,19 +90,21 @@
StringRef::size_type SpaceOffset = Text.find_last_of(Blanks, MaxSplitBytes);
- // Do not split before a number followed by a dot: this would be interpreted
- // as a numbered list, which would prevent re-flowing in subsequent passes.
static auto *const kNumberedListRegexp = new llvm::Regex("^[1-9][0-9]?\\.");
- if (SpaceOffset != StringRef::npos &&
- 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 {.
- if (Style.Language == FormatStyle::LK_JavaScript &&
- SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
- Text[SpaceOffset + 1] == '{')
- SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+ while (SpaceOffset != StringRef::npos) {
+ // Do not split before a number followed by a dot: this would be interpreted
+ // 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 {.
+ else if (Style.Language == FormatStyle::LK_JavaScript &&
+ SpaceOffset + 1 < Text.size() && Text[SpaceOffset + 1] == '{')
+ SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
+ else
+ break;
+ }
if (SpaceOffset == StringRef::npos ||
// Don't break at leading whitespace.
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -2067,6 +2067,14 @@
" * @param {canWrap onSpace}\n"
" */",
getGoogleJSStyleWithColumns(20));
+ // make sure clang-format doesn't break before *any* '{'
+ verifyFormat("/**\n"
+ " * @lala {lala {lalala\n"
+ " */\n",
+ "/**\n"
+ " * @lala {lala {lalala\n"
+ " */\n",
+ getGoogleJSStyleWithColumns(20));
verifyFormat("/**\n"
" * @see http://very/very/long/url/is/long\n"
" */",
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50249.159001.patch
Type: text/x-patch
Size: 2730 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180803/2fcde345/attachment-0001.bin>
More information about the cfe-commits
mailing list