Skip to content

Commit 57b12e8

Browse files
authored
[clangd] Improve robustness when clang-tidy check names contain leading spaces. (#109421)
The current logic assumes that check names do not have leading spaces. In cases like "-*, clang-diagnostic*", when processing the second check " clang-diagnostics-*" (with a leading space), the check fails on `CDPrefix.starts_with(Check)`, resulting in all diagnostics remaining disabled.
1 parent ef44e46 commit 57b12e8

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

clang-tools-extra/clangd/ParsedAST.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,8 @@ class TidyDiagnosticGroups {
280280
llvm::StringRef Check;
281281
while (!Checks.empty()) {
282282
std::tie(Check, Checks) = Checks.split(',');
283+
Check = Check.trim();
284+
283285
if (Check.empty())
284286
continue;
285287

clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,10 @@ TEST(DiagnosticTest, ClangTidyEnablesClangWarning) {
748748
TU.ExtraArgs = {"-Wunused"};
749749
TU.ClangTidyProvider = addClangArgs({"-Wno-unused"}, {});
750750
EXPECT_THAT(TU.build().getDiagnostics(), IsEmpty());
751+
752+
TU.ExtraArgs = {"-Wno-unused"};
753+
TU.ClangTidyProvider = addClangArgs({"-Wunused"}, {"-*, clang-diagnostic-*"});
754+
EXPECT_THAT(TU.build().getDiagnostics(), SizeIs(1));
751755
}
752756

753757
TEST(DiagnosticTest, LongFixMessages) {

0 commit comments

Comments
 (0)