From: Eric Liu Date: Wed, 3 Apr 2019 09:25:16 +0000 (+0000) Subject: [clang-format] Regroup #includes into blocks for Google style X-Git-Tag: llvmorg-10-init~8599 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=0f4d5f85191c124d13046ceabc04d5861ae7ab6a;p=platform%2Fupstream%2Fllvm.git [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 llvm-svn: 357567 --- diff --git a/clang/lib/Format/Format.cpp b/clang/lib/Format/Format.cpp index 119be9f..4dee599 100644 --- a/clang/lib/Format/Format.cpp +++ b/clang/lib/Format/Format.cpp @@ -784,6 +784,7 @@ FormatStyle getGoogleStyle(FormatStyle::LanguageKind Language) { GoogleStyle.IncludeStyle.IncludeCategories = { {"^", 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; diff --git a/clang/unittests/Format/CleanupTest.cpp b/clang/unittests/Format/CleanupTest.cpp index 6afa56e..0628c38 100644 --- a/clang/unittests/Format/CleanupTest.cpp +++ b/clang/unittests/Format/CleanupTest.cpp @@ -420,8 +420,10 @@ TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortLLVM) { TEST_F(CleanUpReplacementsTest, InsertMultipleNewHeadersAndSortGoogle) { std::string Code = "\nint x;"; std::string Expected = "\n#include \"fix.h\"\n" + "\n" "#include \n" "#include \n" + "\n" "#include \"a.h\"\n" "#include \"b.h\"\n" "#include \"c.h\"\n" diff --git a/clang/unittests/Format/SortIncludesTest.cpp b/clang/unittests/Format/SortIncludesTest.cpp index 75f4156..836d4c3 100644 --- a/clang/unittests/Format/SortIncludesTest.cpp +++ b/clang/unittests/Format/SortIncludesTest.cpp @@ -262,9 +262,13 @@ TEST_F(SortIncludesTest, CommentsAlwaysSeparateGroups) { TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { EXPECT_EQ("#include \"a.h\"\n" "#include \"c.h\"\n" + "#include \n" "#include \n" - "#include \n", - sort("#include \n" + "#include \n" + "#include \n", + sort("#include \n" + "#include \n" + "#include \n" "#include \n" "#include \"c.h\"\n" "#include \"a.h\"\n")); @@ -272,9 +276,15 @@ TEST_F(SortIncludesTest, HandlesAngledIncludesAsSeparateBlocks) { FmtStyle = getGoogleStyle(FormatStyle::LK_Cpp); EXPECT_EQ("#include \n" "#include \n" + "\n" + "#include \n" + "#include \n" + "\n" "#include \"a.h\"\n" "#include \"c.h\"\n", - sort("#include \n" + sort("#include \n" + "#include \n" + "#include \n" "#include \n" "#include \"c.h\"\n" "#include \"a.h\"\n"));