diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-16 11:20:47 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2020-03-16 14:08:17 +0100 |
commit | 3e57c56aa1d54ac4587284727ca9c952d33f3e43 (patch) | |
tree | 751d0f973c9e440fbfa24af68b3ed508b167bc52 | |
parent | 61413825960870ac9390d0aa0431702431c620f2 (diff) |
qmllint: Add QFont to the list of unknown builtins
And also check them when analyzing JavaScript access.
Task-number: QTBUG-82817
Change-Id: I677e7883fb24ab80ff20d1998e2d7df440ef4112
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r-- | tests/auto/qml/qmllint/data/ButtonLoader.qml | 10 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 1 | ||||
-rw-r--r-- | tools/qmllint/scopetree.cpp | 28 |
3 files changed, 28 insertions, 11 deletions
diff --git a/tests/auto/qml/qmllint/data/ButtonLoader.qml b/tests/auto/qml/qmllint/data/ButtonLoader.qml new file mode 100644 index 0000000000..2721614735 --- /dev/null +++ b/tests/auto/qml/qmllint/data/ButtonLoader.qml @@ -0,0 +1,10 @@ +import QtQuick 2.12 + +Item { + Text { + id: roundButton + Text { + font.pixelSize: roundButton.font.pixelSize * 0.5 + } + } +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 1cd9f8b0d1..f1930d3caf 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -192,6 +192,7 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("goodParent") << QStringLiteral("goodParent.qml"); QTest::newRow("goodTypeAssertion") << QStringLiteral("goodTypeAssertion.qml"); QTest::newRow("AttachedProps") << QStringLiteral("AttachedProps.qml"); + QTest::newRow("unknownBuiltinFont") << QStringLiteral("ButtonLoader.qml"); } void TestQmllint::cleanQmlCode() diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp index e7e0113f35..5c0fa526a4 100644 --- a/tools/qmllint/scopetree.cpp +++ b/tools/qmllint/scopetree.cpp @@ -134,6 +134,15 @@ private: QStringRef m_afterText; }; +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 +}; + bool ScopeTree::checkMemberAccess( const QString &code, FieldMemberList *members, @@ -169,10 +178,14 @@ bool ScopeTree::checkMemberAccess( } return true; } - const ScopeTree *type = (scopeIt->type() && access->m_parentType.isEmpty()) - ? scopeIt->type() - : types.value(typeName).get(); - return checkMemberAccess(code, access.get(), type, types, colorOut); + + if (const ScopeTree *type = scopeIt->type()) { + if (access->m_parentType.isEmpty()) + return checkMemberAccess(code, access.get(), type, types, colorOut); + } + + return unknownBuiltins.contains(typeName) || checkMemberAccess( + code, access.get(), types.value(typeName).get(), types, colorOut); } const auto scopeMethodIt = scope->m_methods.find(access->m_name); @@ -251,13 +264,6 @@ bool ScopeTree::checkMemberAccess( return false; } -static const QStringList unknownBuiltins = { - QStringLiteral("alias"), // TODO: we cannot properly resolve aliases, yet - QStringLiteral("QRectF"), // TODO: should be added to builtins.qmltypes - QStringLiteral("QJSValue"), // We cannot say anything intelligent about untyped JS values. - QStringLiteral("variant"), // Same for generic variants -}; - bool ScopeTree::recheckIdentifiers( const QString &code, const QHash<QString, const ScopeTree *> &qmlIDs, |