[clang-tools-extra] 2b21fc5 - Allow newline characters as separators for checks in Clang-Tidy configurations
Aaron Ballman via cfe-commits
cfe-commits at lists.llvm.org
Tue Mar 15 11:30:22 PDT 2022
Author: Danny Mösch
Date: 2022-03-15T14:30:13-04:00
New Revision: 2b21fc5520b39fba555f4e5f2480a5651056be84
URL: https://github.com/llvm/llvm-project/commit/2b21fc5520b39fba555f4e5f2480a5651056be84
DIFF: https://github.com/llvm/llvm-project/commit/2b21fc5520b39fba555f4e5f2480a5651056be84.diff
LOG: Allow newline characters as separators for checks in Clang-Tidy configurations
This is a fix for #53737. In addition to commas, newline characters are
considered as separators of checks.
Added:
Modified:
clang-tools-extra/clang-tidy/GlobList.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp
index a55cac412cf63..15d856ea3e10c 100644
--- a/clang-tools-extra/clang-tidy/GlobList.cpp
+++ b/clang-tools-extra/clang-tidy/GlobList.cpp
@@ -27,7 +27,7 @@ static bool consumeNegativeIndicator(StringRef &GlobList) {
// Converts first glob from the comma-separated list of globs to Regex and
// removes it and the trailing comma from the GlobList.
static llvm::Regex consumeGlob(StringRef &GlobList) {
- StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find(','));
+ StringRef UntrimmedGlob = GlobList.substr(0, GlobList.find_first_of(",\n"));
StringRef Glob = UntrimmedGlob.trim();
GlobList = GlobList.substr(UntrimmedGlob.size() + 1);
SmallString<128> RegexText("^");
@@ -44,7 +44,7 @@ static llvm::Regex consumeGlob(StringRef &GlobList) {
}
GlobList::GlobList(StringRef Globs, bool KeepNegativeGlobs /* =true */) {
- Items.reserve(Globs.count(',') + 1);
+ Items.reserve(Globs.count(',') + Globs.count('\n') + 1);
do {
GlobListItem Item;
Item.IsPositive = !consumeNegativeIndicator(Globs);
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
index c4fb8bd7b7563..41621aad7d4f0 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -86,6 +86,20 @@ TEST(ParseConfiguration, ValidConfiguration) {
EXPECT_EQ("some.user", *Options->User);
}
+TEST(ParseConfiguration, ChecksSeparatedByNewlines) {
+ auto MemoryBuffer = llvm::MemoryBufferRef("Checks: |\n"
+ " -*,misc-*\n"
+ " llvm-*\n"
+ " -clang-*,\n"
+ " google-*",
+ "Options");
+
+ auto Options = parseConfiguration(MemoryBuffer);
+
+ EXPECT_TRUE(!!Options);
+ EXPECT_EQ("-*,misc-*\nllvm-*\n-clang-*,\ngoogle-*\n", *Options->Checks);
+}
+
TEST(ParseConfiguration, MergeConfigurations) {
llvm::ErrorOr<ClangTidyOptions> Options1 =
parseConfiguration(llvm::MemoryBufferRef(R"(
diff --git a/clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp b/clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
index 9460a10683fec..833ba78351d4c 100644
--- a/clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
+++ b/clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
@@ -104,5 +104,18 @@ TYPED_TEST(GlobListTest, Complex) {
EXPECT_TRUE(Filter.contains("asdfqwEasdf"));
}
+TYPED_TEST(GlobListTest, NewlineCharactersAsSeparators) {
+ TypeParam Filter("a* \n b,\n-c*,dd");
+
+ EXPECT_FALSE(Filter.contains(""));
+ EXPECT_TRUE(Filter.contains("aaa"));
+ EXPECT_TRUE(Filter.contains("b"));
+ EXPECT_FALSE(Filter.contains("c"));
+ EXPECT_FALSE(Filter.contains("ccc"));
+ EXPECT_FALSE(Filter.contains("d"));
+ EXPECT_TRUE(Filter.contains("dd"));
+ EXPECT_FALSE(Filter.contains("ddd"));
+}
+
} // namespace tidy
} // namespace clang
More information about the cfe-commits
mailing list