[PATCH] D120187: [clang-tidy] Allow newline characters as separators for checks in Clang-Tidy configurations
Danny Mösch via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sat Feb 19 13:08:32 PST 2022
SimplyDanny updated this revision to Diff 410102.
SimplyDanny added a comment.
Update according to comments in review
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D120187/new/
https://reviews.llvm.org/D120187
Files:
clang-tools-extra/clang-tidy/GlobList.cpp
clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
Index: clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp
@@ -104,5 +104,18 @@
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
Index: clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
===================================================================
--- clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp
@@ -86,6 +86,20 @@
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"(
Index: clang-tools-extra/clang-tidy/GlobList.cpp
===================================================================
--- clang-tools-extra/clang-tidy/GlobList.cpp
+++ clang-tools-extra/clang-tidy/GlobList.cpp
@@ -27,7 +27,7 @@
// 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 @@
}
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);
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120187.410102.patch
Type: text/x-patch
Size: 2840 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220219/8dbb191f/attachment-0001.bin>
More information about the cfe-commits
mailing list