diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-20 14:20:48 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-01-21 08:45:16 +0100 |
commit | 39944e8467e5e5d4457e9fec202413adf0fbb2d2 (patch) | |
tree | abf0b4dd17837649a42e0860be754f4f321d9aca /tools | |
parent | 90be89d771425044a84e9e79e4e668e065acc825 (diff) |
qmllint: Remove exceptions for most unknown builtins
All those types are properly defined in the qmltypes files now. We just
need to search the enumerations the same way as methods and properties
in order to find everything.
Also, deduplicate the code that resolves properties, methods, and enums
by using a common template for iterating the scopes.
Change-Id: I0bf1423974d0ec8f602ecd0342522b3e981a8586
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 36 |
1 files changed, 13 insertions, 23 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index 90456f97aa..0517f67ed5 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -56,10 +56,7 @@ private: }; static const QStringList unknownBuiltins = { - // TODO: "string" should be added to builtins.qmltypes, and the special handling below removed QStringLiteral("alias"), // TODO: we cannot properly resolve aliases, yet - QStringLiteral("QRectF"), // TODO: should be added to builtins.qmltypes - QStringLiteral("QFont"), // TODO: should be added to builtins.qmltypes QStringLiteral("QJSValue"), // We cannot say anything intelligent about untyped JS values. QStringLiteral("variant"), // Same for generic variants }; @@ -208,22 +205,19 @@ bool CheckIdentifiers::checkMemberAccess(const QVector<FieldMember> &members, return true; // Access to property of JS function auto checkEnums = [&](const QQmlJSScope::ConstPtr &scope) { - const auto enums = scope->enumerations(); - for (const auto &enumerator : enums) { - if (enumerator.name() == access.m_name) { - detectedRestrictiveKind = QLatin1String("enum"); - detectedRestrictiveName = access.m_name; - expectedNext.append(enumerator.keys()); - return true; - } - for (const QString &key : enumerator.keys()) { - if (access.m_name == key) { - detectedRestrictiveKind = QLatin1String("enum"); - detectedRestrictiveName = access.m_name; - return true; - } - } + if (scope->hasEnumeration(access.m_name)) { + detectedRestrictiveKind = QLatin1String("enum"); + detectedRestrictiveName = access.m_name; + expectedNext.append(scope->enumeration(access.m_name).keys()); + return true; } + + if (scope->hasEnumerationKey(access.m_name)) { + detectedRestrictiveKind = QLatin1String("enum"); + detectedRestrictiveName = access.m_name; + return true; + } + return false; }; @@ -360,10 +354,6 @@ bool CheckIdentifiers::operator()( continue; } - // TODO: Lots of builtins are missing - if (memberAccessBase.m_name == QLatin1String("Qt")) - continue; - const auto typeIt = m_types.find(memberAccessBase.m_name); if (typeIt != m_types.end()) { if (typeIt->isNull()) { @@ -389,7 +379,7 @@ bool CheckIdentifiers::operator()( const auto firstElement = root->childScopes()[0]; if (firstElement->hasProperty(memberAccessBase.m_name) || firstElement->hasMethod(memberAccessBase.m_name) - || firstElement->enumerations().contains(memberAccessBase.m_name)) { + || firstElement->hasEnumeration(memberAccessBase.m_name)) { m_colorOut->writePrefixedMessage( memberAccessBase.m_name + QLatin1String(" is a member of the root element\n") |