diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-18 11:40:31 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-20 08:43:32 +0100 |
commit | 08c8e8ac3ba8eb23ae5c158990f5d029ac9988ed (patch) | |
tree | 2975990abc587af692cf7a6cc3d14bbb01ae70a6 /tools/qmllint | |
parent | 01542a6f25a15e3fb8072db899da7d9cc51d4568 (diff) |
qmllint: Check for existence of property types
For each binding there should be a property and that property should
have a type we recognize.
Enums can be property types in C++. We support this by adding child
scopes for such enums. The child scopes are then referenced by the
QQmlJSMetaEnums and derive from int.
The test then reveals that we were missing a few properties in
QtQuick.tooling. Add those.
Pick-to: 6.1
Change-Id: I1deef94393ee0e17d34c2dc5980ebfbf25417f36
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint')
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 35 |
1 files changed, 34 insertions, 1 deletions
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index c238f874e2..b23d517d41 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -218,8 +218,41 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiScriptBinding *uisb) } const QString signal = signalName(name); - if (signal.isEmpty()) + if (signal.isEmpty()) { + for (const auto &childScope : qmlScope->childScopes()) { + if ((childScope->scopeType() == QQmlJSScope::AttachedPropertyScope + || childScope->scopeType() == QQmlJSScope::GroupedPropertyScope) + && childScope->internalName() == name) { + return true; + } + } + + if (!qmlScope->hasProperty(name.toString())) { + m_errors.append({ + QStringLiteral("Binding assigned to \"%1\", but no property \"%1\" " + "exists in the current element.\n").arg(name), + QtWarningMsg, + uisb->firstSourceLocation() + }); + m_visitFailed = true; + return true; + } + + const auto property = qmlScope->property(name.toString()); + if (!property.type()) { + m_errors.append({ + QStringLiteral("No type found for property \"%1\". This may be due " + "to a missing import statement or incomplete " + "qmltypes files.\n").arg(name), + QtWarningMsg, + uisb->firstSourceLocation() + }); + m_visitFailed = true; + + } + return true; + } if (!qmlScope->hasMethod(signal) && m_warnUnqualified) { |