[PATCH] D24708: clang-format: [JS] Fix line breaks before comments when sorting imports.
Martin Probst via cfe-commits
cfe-commits at lists.llvm.org
Mon Sep 19 00:11:15 PDT 2016
This revision was automatically updated to reflect the committed changes.
Closed by commit rL281888: clang-format: [JS] Fix line breaks before comments when sorting imports. (authored by mprobst).
Changed prior to commit:
https://reviews.llvm.org/D24708?vs=71754&id=71772#toc
Repository:
rL LLVM
https://reviews.llvm.org/D24708
Files:
cfe/trunk/lib/Format/SortJavaScriptImports.cpp
cfe/trunk/unittests/Format/SortImportsTestJS.cpp
Index: cfe/trunk/lib/Format/SortJavaScriptImports.cpp
===================================================================
--- cfe/trunk/lib/Format/SortJavaScriptImports.cpp
+++ cfe/trunk/lib/Format/SortJavaScriptImports.cpp
@@ -293,14 +293,19 @@
// of the import that immediately follows them by using the previously
// set Start.
Start = Line->First->Tok.getLocation();
- if (!Current)
- continue; // Only comments on this line.
+ if (!Current) {
+ // Only comments on this line. Could be the first non-import line.
+ FirstNonImportLine = Line;
+ continue;
+ }
JsModuleReference Reference;
Reference.Range.setBegin(Start);
if (!parseModuleReference(Keywords, Reference)) {
- FirstNonImportLine = Line;
+ if (!FirstNonImportLine)
+ FirstNonImportLine = Line; // if no comment before.
break;
}
+ FirstNonImportLine = nullptr;
AnyImportAffected = AnyImportAffected || Line->Affected;
Reference.Range.setEnd(LineEnd->Tok.getEndLoc());
DEBUG({
Index: cfe/trunk/unittests/Format/SortImportsTestJS.cpp
===================================================================
--- cfe/trunk/unittests/Format/SortImportsTestJS.cpp
+++ cfe/trunk/unittests/Format/SortImportsTestJS.cpp
@@ -121,6 +121,16 @@
"import {sym} from 'b'; // from //foo:bar\n"
"// A very important import follows.\n"
"import {sym} from 'a'; /* more comments */\n");
+ verifySort("import {sym} from 'a';\n"
+ "import {sym} from 'b';\n"
+ "\n"
+ "/** Comment on variable. */\n"
+ "const x = 1;\n",
+ "import {sym} from 'b';\n"
+ "import {sym} from 'a';\n"
+ "\n"
+ "/** Comment on variable. */\n"
+ "const x = 1;\n");
}
TEST_F(SortImportsTestJS, SortStar) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D24708.71772.patch
Type: text/x-patch
Size: 1928 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160919/1e206a1b/attachment.bin>
More information about the cfe-commits
mailing list