diff options
author | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-23 16:10:24 +0200 |
---|---|---|
committer | Fabian Kosmale <fabian.kosmale@qt.io> | 2019-07-26 09:00:07 +0200 |
commit | 66368ffdd93e63a182aa6961f821ca14290ecf80 (patch) | |
tree | 55be6dd8472d9b3afa3301a52e1e4c6fd0b1198f /tests/auto | |
parent | 53e7927fdf56617cfcd3b0e6c9f6db6e0b3d6483 (diff) |
qmllint: Improve parent handling
- Do not warn about parent access in unknown components
This avoids false positive warnings when an imported component could not
be found (or when it actually was not imported).
We still warn about the component which could not be found, so the user
is still informed that something is not right.
We also still emit a warning when we know the properties of a component,
and parent is not one of them.
- Do not recommend the use of parent to address the root components
properties. For this to work, we would need to know whether the root
component reparents its children or not. Moreover, id lookups are
actually faster than parent lookups.
Change-Id: I83d0e71e4bf20d34a3e6d836c2b123b2bf0d416e
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
Diffstat (limited to 'tests/auto')
-rw-r--r-- | tests/auto/qml/qmllint/data/FromRootDirectParent.qml | 14 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/nonSpuriousParentWarning.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/spuriousParentWarning.qml | 7 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/main.cpp | 34 |
4 files changed, 45 insertions, 18 deletions
diff --git a/tests/auto/qml/qmllint/data/FromRootDirectParent.qml b/tests/auto/qml/qmllint/data/FromRootDirectParent.qml deleted file mode 100644 index c0bfd0f26b..0000000000 --- a/tests/auto/qml/qmllint/data/FromRootDirectParent.qml +++ /dev/null @@ -1,14 +0,0 @@ -import QtQuick 2.0 - -Item { - id: root - property int unqualified: 42 - - Item { - x: unqualified // user defined property from root - } - - QtObject { - property int check: x // existing property from root - } -} diff --git a/tests/auto/qml/qmllint/data/nonSpuriousParentWarning.qml b/tests/auto/qml/qmllint/data/nonSpuriousParentWarning.qml new file mode 100644 index 0000000000..a59b736929 --- /dev/null +++ b/tests/auto/qml/qmllint/data/nonSpuriousParentWarning.qml @@ -0,0 +1,8 @@ +import QtQuick 2.12 +import QtQml 2.12 + +Item { + QtObject { + property int x: parent.x + } +} diff --git a/tests/auto/qml/qmllint/data/spuriousParentWarning.qml b/tests/auto/qml/qmllint/data/spuriousParentWarning.qml new file mode 100644 index 0000000000..1323593031 --- /dev/null +++ b/tests/auto/qml/qmllint/data/spuriousParentWarning.qml @@ -0,0 +1,7 @@ +import QtQuick 2.12 + +Item { + Unknown { + property int x: parent.x + } +} diff --git a/tests/auto/qml/qmllint/main.cpp b/tests/auto/qml/qmllint/main.cpp index 1069aa5a33..928575bc82 100644 --- a/tests/auto/qml/qmllint/main.cpp +++ b/tests/auto/qml/qmllint/main.cpp @@ -40,6 +40,7 @@ private Q_SLOTS: void test_data(); void testUnqualified(); void testUnqualified_data(); + void testUnqualifiedNoSpuriousParentWarning(); private: QString m_qmllintPath; }; @@ -73,13 +74,14 @@ void TestQmllint::test_data() void TestQmllint::testUnqualified() { + auto qmlImportDir = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); QFETCH(QString, filename); QFETCH(QString, warningMessage); QFETCH(int, warningLine); QFETCH(int, warningColumn); filename.prepend(QStringLiteral("data/")); QStringList args; - args << QStringLiteral("-U") << filename; + args << QStringLiteral("-U") << filename << QStringLiteral("-I") << qmlImportDir; QProcess process; process.start(m_qmllintPath, args); @@ -106,9 +108,6 @@ void TestQmllint::testUnqualified_data() // access property of root object QTest::newRow("FromRootDirect") << QStringLiteral("FromRoot.qml") << QStringLiteral("x: root.unqualified") << 9 << 16; // new property QTest::newRow("FromRootAccess") << QStringLiteral("FromRoot.qml") << QStringLiteral("property int check: root.x") << 13 << 33; // builtin property - // access property of root object from direct child - QTest::newRow("FromRootDirectParentDirect") << QStringLiteral("FromRootDirectParent.qml") << QStringLiteral("x: parent.unqualified") << 8 << 12; - QTest::newRow("FromRootDirectParentAccess") << QStringLiteral("FromRootDirectParent.qml") << QStringLiteral("property int check: parent.x") << 12 << 29; // access injected name from signal QTest::newRow("SignalHandler1") << QStringLiteral("SignalHandler.qml") << QStringLiteral("onDoubleClicked: function(mouse) {...") << 5 << 21; QTest::newRow("SignalHandler2") << QStringLiteral("SignalHandler.qml") << QStringLiteral("onPositionChanged: function(mouse) {...") << 10 << 21; @@ -117,6 +116,33 @@ void TestQmllint::testUnqualified_data() } +void TestQmllint::testUnqualifiedNoSpuriousParentWarning() +{ + auto qmlImportDir = QLibraryInfo::location(QLibraryInfo::Qml2ImportsPath); + { + QString filename = QLatin1String("spuriousParentWarning.qml"); + filename.prepend(QStringLiteral("data/")); + QStringList args; + args << QStringLiteral("-U") << filename << QStringLiteral("-I") << qmlImportDir; + QProcess process; + process.start(m_qmllintPath, args); + QVERIFY(process.waitForFinished()); + QVERIFY(process.exitStatus() == QProcess::NormalExit); + QVERIFY(process.exitCode() == 0); + } + { + QString filename = QLatin1String("nonSpuriousParentWarning.qml"); + filename.prepend(QStringLiteral("data/")); + QStringList args; + args << QStringLiteral("-U") << filename << QStringLiteral("-I") << qmlImportDir; + QProcess process; + process.start(m_qmllintPath, args); + QVERIFY(process.waitForFinished()); + QVERIFY(process.exitStatus() == QProcess::NormalExit); + QVERIFY(process.exitCode()); + } +} + void TestQmllint::test() { QFETCH(QString, filename); |