From 65b6365ffbde369894f7af1ed735ea34a584d357 Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Wed, 30 Sep 2020 15:03:04 +0200 Subject: qmllint: Remove ScopeTree::m_unmatchedSignalHandlers Rather, immediately output the warnings when we encounter them. Change-Id: I4bd1a5491a47cb0232bfdd4e325f8f122593aa39 Reviewed-by: Maximilian Goldstein Reviewed-by: Fabian Kosmale --- tools/qmllint/checkidentifiers.cpp | 32 ++++++++++++-------------------- tools/qmllint/checkidentifiers.h | 4 +++- tools/qmllint/findwarnings.cpp | 10 ++++++++-- 3 files changed, 23 insertions(+), 23 deletions(-) (limited to 'tools/qmllint') diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 6df5a3fd1a..6366cc72ca 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -69,14 +69,15 @@ static const QStringList unknownBuiltins = { QStringLiteral("variant"), // Same for generic variants }; -void CheckIdentifiers::printContext(const QQmlJS::SourceLocation &location) const +void CheckIdentifiers::printContext( + const QString &code, ColorOutput *output, const QQmlJS::SourceLocation &location) { - IssueLocationWithContext issueLocationWithContext {m_code, location}; - m_colorOut->write(issueLocationWithContext.beforeText().toString(), Normal); - m_colorOut->write(issueLocationWithContext.issueText().toString(), Error); - m_colorOut->write(issueLocationWithContext.afterText().toString() + QLatin1Char('\n'), Normal); + IssueLocationWithContext issueLocationWithContext { code, location }; + output->write(issueLocationWithContext.beforeText().toString(), Normal); + output->write(issueLocationWithContext.issueText().toString(), Error); + output->write(issueLocationWithContext.afterText().toString() + QLatin1Char('\n'), Normal); int tabCount = issueLocationWithContext.beforeText().count(QLatin1Char('\t')); - m_colorOut->write(QString::fromLatin1(" ").repeated( + output->write(QString::fromLatin1(" ").repeated( issueLocationWithContext.beforeText().length() - tabCount) + QString::fromLatin1("\t").repeated(tabCount) + QString::fromLatin1("^").repeated(location.length) @@ -132,7 +133,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & .arg(m_fileName) .arg(access.m_location.startLine) .arg(access.m_location.startColumn), Normal); - printContext(access.m_location); + printContext(m_code, m_colorOut, access.m_location); return false; } @@ -151,7 +152,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & .arg(m_fileName) .arg(access.m_location.startLine) .arg(access.m_location.startColumn), Normal); - printContext(access.m_location); + printContext(m_code, m_colorOut, access.m_location); return false; } @@ -278,7 +279,7 @@ bool CheckIdentifiers::checkMemberAccess(const QVector & .arg(m_fileName) .arg(access.m_location.startLine) .arg(access.m_location.startColumn), Normal); - printContext(access.m_location); + printContext(m_code, m_colorOut, access.m_location); return false; } @@ -297,15 +298,6 @@ bool CheckIdentifiers::operator()( workQueue.enqueue(root); while (!workQueue.empty()) { const ScopeTree::ConstPtr currentScope = workQueue.dequeue(); - const auto unmatchedSignalHandlers = currentScope->unmatchedSignalHandlers(); - for (const auto &handler : unmatchedSignalHandlers) { - writeWarning(m_colorOut); - m_colorOut->write(QString::fromLatin1( - "no matching signal found for handler \"%1\" at %2:%3:%4\n") - .arg(handler.first).arg(m_fileName).arg(handler.second.startLine) - .arg(handler.second.startColumn), Normal); - printContext(handler.second); - } const auto memberAccessChains = currentScope->memberAccessChains(); for (auto memberAccessChain : memberAccessChains) { @@ -360,7 +352,7 @@ bool CheckIdentifiers::operator()( .arg(m_fileName) .arg(memberAccessBase.m_location.startLine) .arg(memberAccessBase.m_location.startColumn), Normal); - printContext(memberAccessBase.m_location); + printContext(m_code, m_colorOut, memberAccessBase.m_location); noUnqualifiedIdentifier = false; } else if (!checkMemberAccess(memberAccessChain, qmlIt->type(), &*qmlIt)) { noUnqualifiedIdentifier = false; @@ -388,7 +380,7 @@ bool CheckIdentifiers::operator()( .arg(location.startLine).arg(location.startColumn), Normal); - printContext(location); + printContext(m_code, m_colorOut, location); // root(JS) --> program(qml) --> (first element) const auto firstElement = root->childScopes()[0]->childScopes()[0]; diff --git a/tools/qmllint/checkidentifiers.h b/tools/qmllint/checkidentifiers.h index 373767420b..2056a80f80 100644 --- a/tools/qmllint/checkidentifiers.h +++ b/tools/qmllint/checkidentifiers.h @@ -51,11 +51,13 @@ public: const QHash &signalHandlers, const ScopeTree::ConstPtr &root, const QString &rootId) const; + static void printContext(const QString &code, ColorOutput *output, + const QQmlJS::SourceLocation &location); + private: bool checkMemberAccess(const QVector &members, const ScopeTree::ConstPtr &outerScope, const MetaProperty *prop = nullptr) const; - void printContext(const QQmlJS::SourceLocation &location) const; ColorOutput *m_colorOut = nullptr; QString m_code; diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 309c7aa6ed..4ace09756f 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -312,8 +312,14 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiScriptBinding *uisb) if (signal.isEmpty()) return true; - if (!m_currentScope->methods().contains(signal)) { - m_currentScope->addUnmatchedSignalHandler(name.toString(), uisb->firstSourceLocation()); + if (!m_currentScope->methods().contains(signal) && m_warnUnqualified) { + const auto location = uisb->firstSourceLocation(); + m_colorOut.write(QLatin1String("Warning: "), Warning); + m_colorOut.write(QString::fromLatin1( + "no matching signal found for handler \"%1\" at %2:%3:%4\n") + .arg(name.toString()).arg(m_filePath).arg(location.startLine) + .arg(location.startColumn), Normal); + CheckIdentifiers::printContext(m_code, &m_colorOut, location); return true; } -- cgit v1.2.3