Author: ioeric Date: Wed Apr 3 02:25:16 2019 New Revision: 357567 URL: http://llvm.org/viewvc/llvm-project?rev=357567&view=rev Log: [clang-format] Regroup #includes into blocks for Google style
Summary: Regrouping #includes in blocks separated by blank lines when sorting C++ #include headers was implemented recently, and it has been preferred in Google's C++ style guide: https://google.github.io/styleguide/cppguide.html#Names_and_Order_of_Includes Reviewers: sammccall, klimek Subscribers: cfe-commits Tags: #clang Differential Revision: https://reviews.llvm.org/D60116 Modified: cfe/trunk/lib/Format/Format.cpp cfe/trunk/unittests/Format/CleanupTest.cpp cfe/trunk/unittests/Format/SortIncludesTest.cpp Modified: cfe/trunk/lib/Format/Format.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=357567&r1=357566&r2=357567&view=diff ============================================================================== --- cfe/trunk/lib/Format/Format.cpp (original) +++ cfe/trunk/lib/Format/Format.cpp Wed Apr 3 02:25:16 2019 @@ -784,6 +784,7 @@ FormatStyle getGoogleStyle(FormatStyle:: 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; Modified: cfe/trunk/unittests/Format/CleanupTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/CleanupTest.cpp?rev=357567&r1=357566&r2=357567&view=diff ============================================================================== --- cfe/trunk/unittests/Format/CleanupTest.cpp (original) +++ cfe/trunk/unittests/Format/CleanupTest.cpp Wed Apr 3 02:25:16 2019 @@ -420,8 +420,10 @@ TEST_F(CleanUpReplacementsTest, InsertMu 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" Modified: cfe/trunk/unittests/Format/SortIncludesTest.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/SortIncludesTest.cpp?rev=357567&r1=357566&r2=357567&view=diff ============================================================================== --- cfe/trunk/unittests/Format/SortIncludesTest.cpp (original) +++ cfe/trunk/unittests/Format/SortIncludesTest.cpp Wed Apr 3 02:25:16 2019 @@ -262,9 +262,13 @@ TEST_F(SortIncludesTest, CommentsAlwaysS 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 @@ TEST_F(SortIncludesTest, HandlesAngledIn 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")); _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits