forked from OSchip/llvm-project
Revert "[clang-format] add case aware include sorting"
This reverts commit 3395a336b0
as there was a post-merge doubt about option naming and type.
This commit is contained in:
parent
2f7baffdc1
commit
6d5c1cd2ab
|
@ -2351,27 +2351,6 @@ the configuration (without a prefix: ``Auto``).
|
||||||
``ClassImpl.hpp`` would not have the main include file put on top
|
``ClassImpl.hpp`` would not have the main include file put on top
|
||||||
before any other include.
|
before any other include.
|
||||||
|
|
||||||
**IncludeSortAlphabetically** (``bool``)
|
|
||||||
Specify if sorting should be done in an alphabetical and
|
|
||||||
case sensitive fashion.
|
|
||||||
|
|
||||||
When ``false``, includes are sorted in an ASCIIbetical
|
|
||||||
fashion.
|
|
||||||
When ``true``, includes are sorted in an alphabetical
|
|
||||||
fashion with case used as a tie-breaker.
|
|
||||||
|
|
||||||
|
|
||||||
.. code-block:: c++
|
|
||||||
|
|
||||||
false: true:
|
|
||||||
#include "A/B.h" vs. #include "A/B.h"
|
|
||||||
#include "A/b.h" #include "A/b.h"
|
|
||||||
#include "B/A.h" #include "a/b.h"
|
|
||||||
#include "B/a.h" #include "B/A.h"
|
|
||||||
#include "a/b.h" #include "B/a.h"
|
|
||||||
|
|
||||||
This option is off by default.
|
|
||||||
|
|
||||||
**IndentCaseBlocks** (``bool``)
|
**IndentCaseBlocks** (``bool``)
|
||||||
Indent case label blocks one level from the case label.
|
Indent case label blocks one level from the case label.
|
||||||
|
|
||||||
|
|
|
@ -147,26 +147,6 @@ struct IncludeStyle {
|
||||||
/// ``ClassImpl.hpp`` would not have the main include file put on top
|
/// ``ClassImpl.hpp`` would not have the main include file put on top
|
||||||
/// before any other include.
|
/// before any other include.
|
||||||
std::string IncludeIsMainSourceRegex;
|
std::string IncludeIsMainSourceRegex;
|
||||||
|
|
||||||
/// Specify if sorting should be done in an alphabetical and
|
|
||||||
/// case sensitive fashion.
|
|
||||||
///
|
|
||||||
/// When ``false``, includes are sorted in an ASCIIbetical
|
|
||||||
/// fashion.
|
|
||||||
/// When ``true``, includes are sorted in an alphabetical
|
|
||||||
/// fashion with case used as a tie-breaker.
|
|
||||||
///
|
|
||||||
/// \code
|
|
||||||
/// false: true:
|
|
||||||
/// #include "A/B.h" vs. #include "A/B.h"
|
|
||||||
/// #include "A/b.h" #include "A/b.h"
|
|
||||||
/// #include "B/A.h" #include "a/b.h"
|
|
||||||
/// #include "B/a.h" #include "B/A.h"
|
|
||||||
/// #include "a/b.h" #include "B/a.h"
|
|
||||||
/// \endcode
|
|
||||||
///
|
|
||||||
/// This option is off by default.
|
|
||||||
bool IncludeSortAlphabetically;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace tooling
|
} // namespace tooling
|
||||||
|
|
|
@ -585,8 +585,6 @@ template <> struct MappingTraits<FormatStyle> {
|
||||||
IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
|
IO.mapOptional("IncludeIsMainRegex", Style.IncludeStyle.IncludeIsMainRegex);
|
||||||
IO.mapOptional("IncludeIsMainSourceRegex",
|
IO.mapOptional("IncludeIsMainSourceRegex",
|
||||||
Style.IncludeStyle.IncludeIsMainSourceRegex);
|
Style.IncludeStyle.IncludeIsMainSourceRegex);
|
||||||
IO.mapOptional("IncludeSortAlphabetically",
|
|
||||||
Style.IncludeStyle.IncludeSortAlphabetically);
|
|
||||||
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
|
IO.mapOptional("IndentCaseLabels", Style.IndentCaseLabels);
|
||||||
IO.mapOptional("IndentCaseBlocks", Style.IndentCaseBlocks);
|
IO.mapOptional("IndentCaseBlocks", Style.IndentCaseBlocks);
|
||||||
IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
|
IO.mapOptional("IndentGotoLabels", Style.IndentGotoLabels);
|
||||||
|
@ -957,7 +955,6 @@ FormatStyle getLLVMStyle(FormatStyle::LanguageKind Language) {
|
||||||
{".*", 1, 0, false}};
|
{".*", 1, 0, false}};
|
||||||
LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
|
LLVMStyle.IncludeStyle.IncludeIsMainRegex = "(Test)?$";
|
||||||
LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
|
LLVMStyle.IncludeStyle.IncludeBlocks = tooling::IncludeStyle::IBS_Preserve;
|
||||||
LLVMStyle.IncludeStyle.IncludeSortAlphabetically = false;
|
|
||||||
LLVMStyle.IndentCaseLabels = false;
|
LLVMStyle.IndentCaseLabels = false;
|
||||||
LLVMStyle.IndentCaseBlocks = false;
|
LLVMStyle.IndentCaseBlocks = false;
|
||||||
LLVMStyle.IndentGotoLabels = true;
|
LLVMStyle.IndentGotoLabels = true;
|
||||||
|
@ -2212,23 +2209,10 @@ static void sortCppIncludes(const FormatStyle &Style,
|
||||||
for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
|
for (unsigned i = 0, e = Includes.size(); i != e; ++i) {
|
||||||
Indices.push_back(i);
|
Indices.push_back(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Style.IncludeStyle.IncludeSortAlphabetically) {
|
|
||||||
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
|
|
||||||
const auto LHSFilenameLower = Includes[LHSI].Filename.lower();
|
|
||||||
const auto RHSFilenameLower = Includes[RHSI].Filename.lower();
|
|
||||||
return std::tie(Includes[LHSI].Priority, LHSFilenameLower,
|
|
||||||
Includes[LHSI].Filename) <
|
|
||||||
std::tie(Includes[RHSI].Priority, RHSFilenameLower,
|
|
||||||
Includes[RHSI].Filename);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
|
llvm::stable_sort(Indices, [&](unsigned LHSI, unsigned RHSI) {
|
||||||
return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) <
|
return std::tie(Includes[LHSI].Priority, Includes[LHSI].Filename) <
|
||||||
std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename);
|
std::tie(Includes[RHSI].Priority, Includes[RHSI].Filename);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
|
|
||||||
// The index of the include on which the cursor will be put after
|
// The index of the include on which the cursor will be put after
|
||||||
// sorting/deduplicating.
|
// sorting/deduplicating.
|
||||||
unsigned CursorIndex;
|
unsigned CursorIndex;
|
||||||
|
|
|
@ -15437,8 +15437,6 @@ TEST_F(FormatTest, ParsesConfigurationBools) {
|
||||||
CHECK_PARSE_BOOL(DeriveLineEnding);
|
CHECK_PARSE_BOOL(DeriveLineEnding);
|
||||||
CHECK_PARSE_BOOL(DerivePointerAlignment);
|
CHECK_PARSE_BOOL(DerivePointerAlignment);
|
||||||
CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
|
CHECK_PARSE_BOOL_FIELD(DerivePointerAlignment, "DerivePointerBinding");
|
||||||
CHECK_PARSE_BOOL_FIELD(IncludeStyle.IncludeSortAlphabetically,
|
|
||||||
"IncludeSortAlphabetically");
|
|
||||||
CHECK_PARSE_BOOL(DisableFormat);
|
CHECK_PARSE_BOOL(DisableFormat);
|
||||||
CHECK_PARSE_BOOL(IndentCaseLabels);
|
CHECK_PARSE_BOOL(IndentCaseLabels);
|
||||||
CHECK_PARSE_BOOL(IndentCaseBlocks);
|
CHECK_PARSE_BOOL(IndentCaseBlocks);
|
||||||
|
|
|
@ -598,49 +598,6 @@ TEST_F(SortIncludesTest, MainHeaderIsSeparatedWhenRegroupping) {
|
||||||
"a.cc"));
|
"a.cc"));
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_F(SortIncludesTest, SupportOptionalAlphabeticalSorting) {
|
|
||||||
EXPECT_FALSE(Style.IncludeSortAlphabetically);
|
|
||||||
|
|
||||||
Style.IncludeSortAlphabetically = true;
|
|
||||||
|
|
||||||
EXPECT_EQ("#include \"A/B.h\"\n"
|
|
||||||
"#include \"A/b.h\"\n"
|
|
||||||
"#include \"a/b.h\"\n"
|
|
||||||
"#include \"B/A.h\"\n"
|
|
||||||
"#include \"B/a.h\"\n",
|
|
||||||
sort("#include \"B/a.h\"\n"
|
|
||||||
"#include \"B/A.h\"\n"
|
|
||||||
"#include \"A/B.h\"\n"
|
|
||||||
"#include \"a/b.h\"\n"
|
|
||||||
"#include \"A/b.h\"\n",
|
|
||||||
"a.h"));
|
|
||||||
|
|
||||||
Style.IncludeBlocks = clang::tooling::IncludeStyle::IBS_Regroup;
|
|
||||||
Style.IncludeCategories = {
|
|
||||||
{"^\"", 1, 0, false}, {"^<.*\\.h>$", 2, 0, false}, {"^<", 3, 0, false}};
|
|
||||||
|
|
||||||
StringRef UnsortedCode = "#include \"qt.h\"\n"
|
|
||||||
"#include <algorithm>\n"
|
|
||||||
"#include <qtwhatever.h>\n"
|
|
||||||
"#include <Qtwhatever.h>\n"
|
|
||||||
"#include <Algorithm>\n"
|
|
||||||
"#include \"vlib.h\"\n"
|
|
||||||
"#include \"Vlib.h\"\n"
|
|
||||||
"#include \"AST.h\"\n";
|
|
||||||
|
|
||||||
EXPECT_EQ("#include \"AST.h\"\n"
|
|
||||||
"#include \"qt.h\"\n"
|
|
||||||
"#include \"Vlib.h\"\n"
|
|
||||||
"#include \"vlib.h\"\n"
|
|
||||||
"\n"
|
|
||||||
"#include <Qtwhatever.h>\n"
|
|
||||||
"#include <qtwhatever.h>\n"
|
|
||||||
"\n"
|
|
||||||
"#include <Algorithm>\n"
|
|
||||||
"#include <algorithm>\n",
|
|
||||||
sort(UnsortedCode));
|
|
||||||
}
|
|
||||||
|
|
||||||
TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
|
TEST_F(SortIncludesTest, SupportCaseInsensitiveMatching) {
|
||||||
// Setup an regex for main includes so we can cover those as well.
|
// Setup an regex for main includes so we can cover those as well.
|
||||||
Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
|
Style.IncludeIsMainRegex = "([-_](test|unittest))?$";
|
||||||
|
|
Loading…
Reference in New Issue