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>
This commit is contained in:
Christian Kandeler
2021-06-25 14:16:09 +02:00
parent 74385cc10c
commit 6f5e20bf64

View File

@@ -130,12 +130,27 @@ QString ClangDiagnosticConfig::clangTidyChecksAsJson() const
{
QString jsonString = "{Checks: '" + clangTidyChecks()
+ ",-clang-diagnostic-*', CheckOptions: [";
for (auto it = m_tidyChecksOptions.cbegin(); it != m_tidyChecksOptions.cend(); ++it) {
const int idx = m_clangTidyChecks.indexOf(it.key());
// 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) {
if (!checkIsEnabled(it.key()))
continue;
QString optionString;
for (auto optIt = it.value().begin(); optIt != it.value().end(); ++optIt) {
if (!optionString.isEmpty())