diff options
author | Evgeniy A. Dushistov <dushistov@mail.ru> | 2020-06-17 23:39:28 +0300 |
---|---|---|
committer | Evgeniy A. Dushistov <dushistov@mail.ru> | 2020-06-18 11:21:18 +0300 |
commit | b916c1bffdd4bcaaa6d4d75d2a9efa34a485cff5 (patch) | |
tree | de9498b87eb4bdb2156507b126079f627819fc45 | |
parent | e8d9bc1bcada7d94af5a33d64a9afc860ede5b84 (diff) |
qmllint: high level item can also be list
Fixes: QTBUG-84300
Change-Id: I1a9db060cdeb7c4ec10deedab5141a06245a55b2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
-rw-r--r-- | tests/auto/qml/qmllint/data/ListProperty.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/Things/plugins.qmltypes | 16 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 | ||||
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 11 | ||||
-rw-r--r-- | tools/qmllint/checkidentifiers.h | 3 |
5 files changed, 34 insertions, 3 deletions
diff --git a/tests/auto/qml/qmllint/data/ListProperty.qml b/tests/auto/qml/qmllint/data/ListProperty.qml new file mode 100644 index 0000000000..d2bbc58cc5 --- /dev/null +++ b/tests/auto/qml/qmllint/data/ListProperty.qml @@ -0,0 +1,6 @@ +import QtQuick 2.12 +import Things 1.0 + +Frame { + contentWidth: contentChildren.length === 1 ? contentChildren[0].implicitWidth : 0 +} diff --git a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes index 9d81c21070..95ff95eb7d 100644 --- a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes +++ b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes @@ -14,4 +14,20 @@ Module { } Property { name: "palette"; type: "QPalette" } } + Component { + name: "Frame" + prototype: "MyPane" + exports: ["Things.Templates/Frame 1.0"] + exportMetaObjectRevisions: [0] + } + Component { + name: "MyPane" + prototype: "QObject" + exports: ["Things.Templates/Pane 1.0"] + exportMetaObjectRevisions: [0] + Property { name: "contentWidth"; type: "double" } + Property { name: "contentHeight"; type: "double" } + Property { name: "contentData"; type: "QObject"; isList: true; isReadonly: true } + Property { name: "contentChildren"; type: "QQuickItem"; isList: true; isReadonly: true } + } } diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 2c7998b571..7459a813be 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -222,6 +222,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("qualifiedAttached") << QStringLiteral("Drawer.qml"); QTest::newRow("EnumAccess1") << QStringLiteral("EnumAccess1.qml"); QTest::newRow("EnumAccess2") << QStringLiteral("EnumAccess2.qml"); + QTest::newRow("ListProperty") << QStringLiteral("ListProperty.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index e1593182ab..32eb4ce025 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -83,12 +83,19 @@ void CheckIdentifiers::printContext(const QQmlJS::SourceLocation &location) cons } bool CheckIdentifiers::checkMemberAccess(const QVector<ScopeTree::FieldMember> &members, - const ScopeTree::ConstPtr &outerScope) const + const ScopeTree::ConstPtr &outerScope, + const MetaProperty *prop) const { + QStringList expectedNext; QString detectedRestrictiveName; QString detectedRestrictiveKind; + if (prop != nullptr && prop->isList()) { + detectedRestrictiveKind = QLatin1String("list"); + expectedNext.append(QLatin1String("length")); + } + ScopeTree::ConstPtr scope = outerScope; for (const ScopeTree::FieldMember &access : members) { if (scope.isNull()) { @@ -319,7 +326,7 @@ bool CheckIdentifiers::operator()(const QHash<QString, ScopeTree::ConstPtr> &qml .arg(memberAccessBase.m_location.startColumn), Normal); printContext(memberAccessBase.m_location); noUnqualifiedIdentifier = false; - } else if (!checkMemberAccess(memberAccessChain, qmlIt->type())) { + } else if (!checkMemberAccess(memberAccessChain, qmlIt->type(), &*qmlIt)) { noUnqualifiedIdentifier = false; } diff --git a/tools/qmllint/checkidentifiers.h b/tools/qmllint/checkidentifiers.h index 28f8b24c09..36de88a846 100644 --- a/tools/qmllint/checkidentifiers.h +++ b/tools/qmllint/checkidentifiers.h @@ -46,7 +46,8 @@ public: private: bool checkMemberAccess(const QVector<ScopeTree::FieldMember> &members, - const ScopeTree::ConstPtr &outerScope) const; + const ScopeTree::ConstPtr &outerScope, + const MetaProperty *prop = nullptr) const; void printContext(const QQmlJS::SourceLocation &location) const; ColorOutput *m_colorOut = nullptr; |