diff options
author | Christian Kandeler <christian.kandeler@qt.io> | 2021-06-25 14:16:09 +0200 |
---|---|---|
committer | Christian Kandeler <christian.kandeler@qt.io> | 2021-06-29 06:59:21 +0000 |
commit | 6f5e20bf6419899238f9b8283b6463a323f5c12b (patch) | |
tree | b42c44be2bc55e76e40fdf1ece1553e54ccf5877 /src/plugins/cpptools/clangdiagnosticconfig.cpp | |
parent | 74385cc10c9af17e15999e3ac0f34de85882d2b7 (diff) | |
download | qt-creator-6f5e20bf6419899238f9b8283b6463a323f5c12b.tar.gz |
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 <david.schulz@qt.io>
Diffstat (limited to 'src/plugins/cpptools/clangdiagnosticconfig.cpp')
-rw-r--r-- | src/plugins/cpptools/clangdiagnosticconfig.cpp | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/src/plugins/cpptools/clangdiagnosticconfig.cpp b/src/plugins/cpptools/clangdiagnosticconfig.cpp index c31fc4f8ce..95ba5a7328 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 "<prefix>-*" 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) { |