From 6f5e20bf6419899238f9b8283b6463a323f5c12b Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Fri, 25 Jun 2021 14:16:09 +0200 Subject: [PATCH] ClangTools: Fix applying check options The algorithm we used to determine whether an option was applicable did not take the wildcard syntax into account that is used when all sub- checks of a group are enabled. Fixes: QTCREATORBUG-25827 Change-Id: I1d385bcc90ea9bf0bfac5cffe8739a8148aa740f Reviewed-by: David Schulz --- .../cpptools/clangdiagnosticconfig.cpp | 23 +++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/plugins/cpptools/clangdiagnosticconfig.cpp b/src/plugins/cpptools/clangdiagnosticconfig.cpp index c31fc4f8ce5..95ba5a7328e 100644 --- a/src/plugins/cpptools/clangdiagnosticconfig.cpp +++ b/src/plugins/cpptools/clangdiagnosticconfig.cpp @@ -130,11 +130,26 @@ QString ClangDiagnosticConfig::clangTidyChecksAsJson() const { QString jsonString = "{Checks: '" + clangTidyChecks() + ",-clang-diagnostic-*', CheckOptions: ["; + + // The check is either listed verbatim or covered by the "-*" pattern. + const auto checkIsEnabled = [this](const QString &check) { + for (QString subString = check; !subString.isEmpty(); + subString.chop(subString.length() - subString.lastIndexOf('-'))) { + const int idx = m_clangTidyChecks.indexOf(subString); + if (idx == -1) + continue; + if (idx > 0 && m_clangTidyChecks.at(idx - 1) == '-') + continue; + if (subString == check || QStringView(m_clangTidyChecks) + .mid(idx + subString.length()).startsWith(QLatin1String("-*"))) { + return true; + } + } + return false; + }; + for (auto it = m_tidyChecksOptions.cbegin(); it != m_tidyChecksOptions.cend(); ++it) { - const int idx = m_clangTidyChecks.indexOf(it.key()); - if (idx == -1) - continue; - if (idx > 0 && m_clangTidyChecks.at(idx - 1) == '-') + if (!checkIsEnabled(it.key())) continue; QString optionString; for (auto optIt = it.value().begin(); optIt != it.value().end(); ++optIt) {