aboutsummaryrefslogtreecommitdiffstats
path: root/tools
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2020-09-30 15:03:04 +0200
committerUlf Hermann <ulf.hermann@qt.io>2020-10-02 15:33:17 +0200
commit65b6365ffbde369894f7af1ed735ea34a584d357 (patch)
treeae0fa55acb927ab0b148faa2bc3cf0367e79176e /tools
parent7957752447fbd2581521b13156ef29ffc80ad7bf (diff)
qmllint: Remove ScopeTree::m_unmatchedSignalHandlers
Rather, immediately output the warnings when we encounter them. Change-Id: I4bd1a5491a47cb0232bfdd4e325f8f122593aa39 Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r--tools/qmllint/checkidentifiers.cpp32
-rw-r--r--tools/qmllint/checkidentifiers.h4
-rw-r--r--tools/qmllint/findwarnings.cpp10
-rw-r--r--tools/shared/scopetree.cpp6
-rw-r--r--tools/shared/scopetree.h8
5 files changed, 23 insertions, 37 deletions
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<ScopeTree::FieldMember> &
.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<ScopeTree::FieldMember> &
.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<ScopeTree::FieldMember> &
.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<QQmlJS::SourceLocation, SignalHandler> &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<ScopeTree::FieldMember> &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;
}
diff --git a/tools/shared/scopetree.cpp b/tools/shared/scopetree.cpp
index 933f3f88d7..223dfb92b8 100644
--- a/tools/shared/scopetree.cpp
+++ b/tools/shared/scopetree.cpp
@@ -71,12 +71,6 @@ void ScopeTree::insertPropertyIdentifier(const MetaProperty &property)
addMethod(method);
}
-void ScopeTree::addUnmatchedSignalHandler(const QString &handler,
- const QQmlJS::SourceLocation &location)
-{
- m_unmatchedSignalHandlers.append(qMakePair(handler, location));
-}
-
bool ScopeTree::isIdInCurrentScope(const QString &id) const
{
return isIdInCurrentQMlScopes(id) || isIdInCurrentJSScopes(id);
diff --git a/tools/shared/scopetree.h b/tools/shared/scopetree.h
index b751815172..57a346d0d9 100644
--- a/tools/shared/scopetree.h
+++ b/tools/shared/scopetree.h
@@ -127,8 +127,6 @@ public:
// inserts property as qml identifier as well as the corresponding
void insertPropertyIdentifier(const MetaProperty &prop);
- void addUnmatchedSignalHandler(const QString &handler,
- const QQmlJS::SourceLocation &location);
bool isIdInCurrentScope(const QString &id) const;
void addIdToAccessed(const QString &id, const QQmlJS::SourceLocation &location);
@@ -189,11 +187,6 @@ public:
QQmlJS::SourceLocation m_location;
};
- QVector<QPair<QString, QQmlJS::SourceLocation>> unmatchedSignalHandlers() const
- {
- return m_unmatchedSignalHandlers;
- }
-
QVector<QVector<FieldMember>> memberAccessChains() const
{
return m_memberAccessChains;
@@ -222,7 +215,6 @@ private:
QHash<QString, MetaEnum> m_enums;
QVector<QVector<FieldMember>> m_memberAccessChains;
- QVector<QPair<QString, QQmlJS::SourceLocation>> m_unmatchedSignalHandlers;
QVector<ScopeTree::Ptr> m_childScopes;
ScopeTree::WeakPtr m_parentScope;