[PATCH] D50230: 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 01:53:01 PDT 2018
mprobst created this revision.
mprobst added a reviewer: krasimir.
Previously, clang-format would avoid breaking before the first `{`
found, but then happily break before subsequent '{'s on the line. This
change fixes that by looking for the first location that has no opening
curly, if any.
Repository:
rC Clang
https://reviews.llvm.org/D50230
Files:
lib/Format/BreakableToken.cpp
unittests/Format/FormatTestJS.cpp
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"
" */",
Index: lib/Format/BreakableToken.cpp
===================================================================
--- lib/Format/BreakableToken.cpp
+++ lib/Format/BreakableToken.cpp
@@ -99,7 +99,7 @@
// 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 &&
+ while (Style.Language == FormatStyle::LK_JavaScript &&
SpaceOffset != StringRef::npos && SpaceOffset + 1 < Text.size() &&
Text[SpaceOffset + 1] == '{')
SpaceOffset = Text.find_last_of(Blanks, SpaceOffset);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D50230.158945.patch
Type: text/x-patch
Size: 1413 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180803/50e805ff/attachment.bin>
More information about the cfe-commits
mailing list