[PATCH] D60116: [clang-format] Regroup #includes into blocks for Google style

Eric Liu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed Apr 3 02:23:53 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rC357567: [clang-format] Regroup #includes into blocks for Google style (authored by ioeric, committed by ).

Changed prior to commit:
  https://reviews.llvm.org/D60116?vs=193446&id=193452#toc

Repository:
  rC Clang

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D60116/new/

https://reviews.llvm.org/D60116

Files:
  lib/Format/Format.cpp
  unittests/Format/CleanupTest.cpp
  unittests/Format/SortIncludesTest.cpp


Index: lib/Format/Format.cpp
===================================================================
--- lib/Format/Format.cpp
+++ lib/Format/Format.cpp
@@ -784,6 +784,7 @@
   GoogleStyle.IncludeStyle.IncludeCategories = {
       {"^<ext/.*\\.h>", 2}, {"^<.*\\.h>", 1}, {"^<.*", 2}, {".*", 3}};
   GoogleStyle.IncludeStyle.IncludeIsMainRegex = "([-_](test|unittest))?$";
+  GoogleStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Regroup;
   GoogleStyle.IndentCaseLabels = true;
   GoogleStyle.KeepEmptyLinesAtTheStartOfBlocks = false;
   GoogleStyle.ObjCBinPackProtocolList = FormatStyle::BPS_Never;
Index: unittests/Format/CleanupTest.cpp
===================================================================
--- unittests/Format/CleanupTest.cpp
+++ unittests/Format/CleanupTest.cpp
@@ -420,8 +420,10 @@
 TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortGoogle) {
   std::string Code = "\nint x;";
   std::string Expected = "\n#include \"fix.h\"\n"
+                         "\n"
                          "#include <list>\n"
                          "#include <vector>\n"
+                         "\n"
                          "#include \"a.h\"\n"
                          "#include \"b.h\"\n"
                          "#include \"c.h\"\n"
Index: unittests/Format/SortIncludesTest.cpp
===================================================================
--- unittests/Format/SortIncludesTest.cpp
+++ unittests/Format/SortIncludesTest.cpp
@@ -262,9 +262,13 @@
 TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) {
   EXPECT_EQ("#include \"a.h\"\n"
             "#include \"c.h\"\n"
+            "#include <array>\n"
             "#include <b.h>\n"
-            "#include <d.h>\n",
-            sort("#include <d.h>\n"
+            "#include <d.h>\n"
+            "#include <vector>\n",
+            sort("#include <vector>\n"
+                 "#include <d.h>\n"
+                 "#include <array>\n"
                  "#include <b.h>\n"
                  "#include \"c.h\"\n"
                  "#include \"a.h\"\n"));
@@ -272,9 +276,15 @@
   FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp);
   EXPECT_EQ("#include <b.h>\n"
             "#include <d.h>\n"
+            "\n"
+            "#include <array>\n"
+            "#include <vector>\n"
+            "\n"
             "#include \"a.h\"\n"
             "#include \"c.h\"\n",
-            sort("#include <d.h>\n"
+            sort("#include <vector>\n"
+                 "#include <d.h>\n"
+                 "#include <array>\n"
                  "#include <b.h>\n"
                  "#include \"c.h\"\n"
                  "#include \"a.h\"\n"));


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D60116.193452.patch
Type: text/x-patch
Size: 2640 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190403/02c9ed30/attachment.bin>


More information about the cfe-commits mailing list