summaryrefslogtreecommitdiff
path: root/src/plugins/cpptools/clangdiagnosticconfig.cpp
diff options
context:
space:
mode:
authorChristian Kandeler <christian.kandeler@qt.io>2021-06-25 14:16:09 +0200
committerChristian Kandeler <christian.kandeler@qt.io>2021-06-29 06:59:21 +0000
commit6f5e20bf6419899238f9b8283b6463a323f5c12b (patch)
treeb42c44be2bc55e76e40fdf1ece1553e54ccf5877 /src/plugins/cpptools/clangdiagnosticconfig.cpp
parent74385cc10c9af17e15999e3ac0f34de85882d2b7 (diff)
downloadqt-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.cpp23
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) {