diff options
-rw-r--r-- | tests/auto/qml/qmllint/data/anchors1.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/anchors3.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/nanchors1.qml | 8 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/nanchors3.qml | 6 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 48 | ||||
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 7 |
6 files changed, 70 insertions, 13 deletions
diff --git a/tests/auto/qml/qmllint/data/anchors1.qml b/tests/auto/qml/qmllint/data/anchors1.qml new file mode 100644 index 0000000000..6a487fa757 --- /dev/null +++ b/tests/auto/qml/qmllint/data/anchors1.qml @@ -0,0 +1,8 @@ +import QtQuick 2.15 + +Rectangle { + anchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } +} diff --git a/tests/auto/qml/qmllint/data/anchors3.qml b/tests/auto/qml/qmllint/data/anchors3.qml new file mode 100644 index 0000000000..290b19f98b --- /dev/null +++ b/tests/auto/qml/qmllint/data/anchors3.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 + +Rectangle { + anchors.horizontalCenter: parent + anchors.verticalCenter: parent +} diff --git a/tests/auto/qml/qmllint/data/nanchors1.qml b/tests/auto/qml/qmllint/data/nanchors1.qml new file mode 100644 index 0000000000..7331a68614 --- /dev/null +++ b/tests/auto/qml/qmllint/data/nanchors1.qml @@ -0,0 +1,8 @@ +import QtQuick 2.15 + +Rectangle { + nanchors { + horizontalCenter: parent.horizontalCenter + verticalCenter: parent.verticalCenter + } +} diff --git a/tests/auto/qml/qmllint/data/nanchors3.qml b/tests/auto/qml/qmllint/data/nanchors3.qml new file mode 100644 index 0000000000..4ba987ed9c --- /dev/null +++ b/tests/auto/qml/qmllint/data/nanchors3.qml @@ -0,0 +1,6 @@ +import QtQuick 2.15 + +Rectangle { + nanchors.horizontalCenter: parent + nanchors.verticalCenter: parent +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 1a36986663..cd0042d291 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -53,7 +53,11 @@ private Q_SLOTS: void directoryPassedAsQmlTypesFile(); private: - QString runQmllint(const QString &fileToLint, bool shouldSucceed, const QStringList &extraArgs = QStringList()); + QString runQmllint(const QString &fileToLint, + std::function<void(QProcess &)> handleResult, + const QStringList &extraArgs = QStringList()); + QString runQmllint(const QString &fileToLint, bool shouldSucceed, + const QStringList &extraArgs = QStringList()); QString m_qmllintPath; }; @@ -195,6 +199,14 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("badEnumFromQtQml.qml") << QString("Warning: Property \"Linear123\" not found on type \"QQmlEasingEnums\"") << QString(); + QTest::newRow("nanchors1") + << QStringLiteral("nanchors1.qml") + << QString() + << QString(); + QTest::newRow("nanchors3") + << QStringLiteral("nanchors3.qml") + << QString() + << QString(); } void TestQmllint::dirtyQmlCode() @@ -205,7 +217,14 @@ void TestQmllint::dirtyQmlCode() if (warningMessage.contains(QLatin1String("%1"))) warningMessage = warningMessage.arg(testFile(filename)); - const QString output = runQmllint(filename, false); + const QString output = runQmllint(filename, [&](QProcess &process) { + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + QEXPECT_FAIL("nanchors1", "Invalid grouped properties are not detected", Abort); + QEXPECT_FAIL("nanchors3", "Invalid grouped properties are not detected", Abort); + QVERIFY(process.exitCode() != 0); + }); + QVERIFY(output.contains(warningMessage)); if (!notContained.isEmpty()) QVERIFY(!output.contains(notContained)); @@ -242,6 +261,8 @@ void TestQmllint::cleanQmlCode_data() QTest::newRow("javascriptMethodsInModule") << QStringLiteral("javascriptMethodsInModuleGood.qml"); QTest::newRow("enumFromQtQml") << QStringLiteral("enumFromQtQml.qml"); + QTest::newRow("anchors1") << QStringLiteral("anchors1.qml"); + QTest::newRow("anchors3") << QStringLiteral("anchors3.qml"); } void TestQmllint::cleanQmlCode() @@ -251,7 +272,9 @@ void TestQmllint::cleanQmlCode() QVERIFY(warnings.isEmpty()); } -QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, const QStringList &extraArgs) +QString TestQmllint::runQmllint(const QString &fileToLint, + std::function<void(QProcess &)> handleResult, + const QStringList &extraArgs) { auto qmlImportDir = QLibraryInfo::path(QLibraryInfo::Qml2ImportsPath); QStringList args; @@ -264,12 +287,7 @@ QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, c auto verify = [&](bool isSilent) { QProcess process; process.start(m_qmllintPath, args); - QVERIFY(process.waitForFinished()); - QCOMPARE(process.exitStatus(), QProcess::NormalExit); - if (shouldSucceed) - QCOMPARE(process.exitCode(), 0); - else - QVERIFY(process.exitCode() != 0); + handleResult(process); errors = process.readAllStandardError(); if (isSilent) @@ -281,5 +299,17 @@ QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, c return errors; } +QString TestQmllint::runQmllint(const QString &fileToLint, bool shouldSucceed, const QStringList &extraArgs) +{ + return runQmllint(fileToLint, [&](QProcess &process) { + QVERIFY(process.waitForFinished()); + QCOMPARE(process.exitStatus(), QProcess::NormalExit); + if (shouldSucceed) + QCOMPARE(process.exitCode(), 0); + else + QVERIFY(process.exitCode() != 0); + }, extraArgs); +} + QTEST_MAIN(TestQmllint) #include "tst_qmllint.moc" diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 0131921928..fb69756415 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -831,14 +831,13 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiObjectDefinition *uiod) name += id->name.toString() + QLatin1Char('.'); name.chop(1); - enterEnvironment(ScopeType::QMLScope, name); - m_currentScope->resolveTypes(m_rootScopeImports.importedQmlNames); - importExportedNames(m_currentScope); - if (name.isLower()) return false; // Ignore grouped properties for now + m_currentScope->resolveTypes(m_rootScopeImports.importedQmlNames); + importExportedNames(m_currentScope); + if (name.endsWith("Connections")) { QString target; auto member = uiod->initializer->members; |