[PATCH] D18283: clang-format: [JS] do not break location pragma comments.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Fri Mar 18 14:46:55 PDT 2016
mprobst created this revision.
mprobst added reviewers: djasper, klimek, cfe-commits.
Herald added a subscriber: klimek.
`import ... from ...; // from //foo:bar` serves as the equivalent if an IWYU
pragma. This change matches `// from //.*` style comments and never allows them
to wrap, just like IWYU pragmas for C++.
For the time being, it does not seem worth turning this into a configurable
option.
http://reviews.llvm.org/D18283
Files:
lib/Format/ContinuationIndenter.cpp
unittests/Format/FormatTestJS.cpp
Index: unittests/Format/FormatTestJS.cpp
===================================================================
--- unittests/Format/FormatTestJS.cpp
+++ unittests/Format/FormatTestJS.cpp
@@ -1188,5 +1188,15 @@
verifyFormat("var x = 'foo';", LeaveQuotes);
}
+
+TEST_F(FormatTestJS, LocationComment) {
+ verifyFormat("import {\n"
+ " x\n"
+ "} from\n"
+ " 'asd'; // from //some/really/long/path/here",
+ "import {x} from 'asd'; // from //some/really/long/path/here",
+ getGoogleJSStyleWithColumns(25));
+}
+
} // end namespace tooling
} // end namespace clang
Index: lib/Format/ContinuationIndenter.cpp
===================================================================
--- lib/Format/ContinuationIndenter.cpp
+++ lib/Format/ContinuationIndenter.cpp
@@ -1059,6 +1059,8 @@
return 0;
}
+static llvm::Regex JSImportLocationCommentRegex("^//[ \n\t]*from[ \n\t]+//");
+
unsigned ContinuationIndenter::breakProtrudingToken(const FormatToken &Current,
LineState &State,
bool DryRun) {
@@ -1137,6 +1139,10 @@
if (!Style.ReflowComments ||
CommentPragmasRegex.match(Current.TokenText.substr(2)))
return 0;
+ if (Style.Language == FormatStyle::LK_JavaScript &&
+ JSImportLocationCommentRegex.match(Current.TokenText))
+ return 0;
+
Token.reset(new BreakableLineComment(Current, State.Line->Level,
StartColumn, /*InPPDirective=*/false,
Encoding, Style));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D18283.51075.patch
Type: text/x-patch
Size: 1662 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160318/b46b1149/attachment.bin>
More information about the cfe-commits
mailing list