diff --git a/.clang-tidy b/.clang-tidy --- a/.clang-tidy +++ b/.clang-tidy @@ -1,4 +1,13 @@ -Checks: '-*,clang-diagnostic-*,llvm-*,misc-*,-misc-unused-parameters,-misc-non-private-member-variables-in-classes,-misc-no-recursion,readability-identifier-naming' +Checks: | + -* + clang-diagnostic-* + llvm-* + misc-* + -misc-unused-parameters + -misc-non-private-member-variables-in-classes + -misc-no-recursion + readability-identifier-naming + CheckOptions: - key: readability-identifier-naming.ClassCase value: CamelCase diff --git a/clang-tools-extra/clang-tidy/GlobList.cpp b/clang-tools-extra/clang-tidy/GlobList.cpp --- a/clang-tools-extra/clang-tidy/GlobList.cpp +++ b/clang-tools-extra/clang-tidy/GlobList.cpp @@ -27,7 +27,8 @@ // 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(',')); + auto NextSplitIndex = std::min(GlobList.find(','), GlobList.find('\n')); + StringRef UntrimmedGlob = GlobList.substr(0, NextSplitIndex); StringRef Glob = UntrimmedGlob.trim(); GlobList = GlobList.substr(UntrimmedGlob.size() + 1); SmallString<128> RegexText("^"); @@ -44,7 +45,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); diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp b/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp --- a/clang-tools-extra/unittests/clang-tidy/ClangTidyOptionsTest.cpp +++ b/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 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 --- a/clang-tools-extra/unittests/clang-tidy/GlobListTest.cpp +++ b/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