aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-06-21 15:03:19 +0200
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2021-06-22 13:00:55 +0000
commit1b2167d935ee19f2cb2c6d7bb0b557e6a8eb3485 (patch)
tree92d505bd0e547693137fe3f96781cc92fbf74d70
parent90db5baa28ffa78422332f4e7973fe603496ba34 (diff)
qmllint: Ignore unqualified access in custom parser components
We currently can't handle all special cases with custom parsers (i.e. signal transitions) so we need to ignore unqualified accesses except for those specific instances where we already have some special handling implemented (e.g. Connections). Task-number: QTBUG-77417 Change-Id: Iea86d4b56e56091c7acffc29a0259de412fa1624 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> (cherry picked from commit 4063895a28bb454995d6b4ee57e4f2c3b5dcc5d7) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
-rw-r--r--tests/auto/qml/qmllint/data/Things/plugins.qmltypes9
-rw-r--r--tests/auto/qml/qmllint/data/customParserUnqualifiedAccess.qml5
-rw-r--r--tests/auto/qml/qmllint/tst_qmllint.cpp2
-rw-r--r--tools/qmllint/checkidentifiers.cpp10
4 files changed, 26 insertions, 0 deletions
diff --git a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
index 9ad8c71468..7d0514dbdf 100644
--- a/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
+++ b/tests/auto/qml/qmllint/data/Things/plugins.qmltypes
@@ -64,4 +64,13 @@ Module {
]
Property { name: "alignment"; type: "Qt::Alignment" }
}
+ Component {
+ name: "CustomParserThing"
+ prototype: "QQuickItem"
+ exports: [
+ "Things/CustomParserThing 1.0"
+ ]
+ Property { name: "foo"; type: "string" }
+ hasCustomParser: true
+ }
}
diff --git a/tests/auto/qml/qmllint/data/customParserUnqualifiedAccess.qml b/tests/auto/qml/qmllint/data/customParserUnqualifiedAccess.qml
new file mode 100644
index 0000000000..dc8f814c91
--- /dev/null
+++ b/tests/auto/qml/qmllint/data/customParserUnqualifiedAccess.qml
@@ -0,0 +1,5 @@
+import Things
+
+CustomParserThing {
+ foo: does.not.exist
+}
diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp
index 4c40062252..cfd97e33fb 100644
--- a/tests/auto/qml/qmllint/tst_qmllint.cpp
+++ b/tests/auto/qml/qmllint/tst_qmllint.cpp
@@ -758,6 +758,8 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("InlineComponentsChained") << QStringLiteral("inlineComponentsChained.qml");
QTest::newRow("ignoreWarnings") << QStringLiteral("ignoreWarnings.qml");
QTest::newRow("BindingBeforeDeclaration") << QStringLiteral("bindingBeforeDeclaration.qml");
+ QTest::newRow("CustomParserUnqualifiedAccess")
+ << QStringLiteral("customParserUnqualifiedAccess.qml");
}
void TestQmllint::cleanQmlCode()
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index 93edb08ba0..ac8453b1cd 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -384,6 +384,16 @@ void CheckIdentifiers::operator()(
continue;
}
+ // If we're in a custom parser component (or one of their children) we cannot be sure
+ // that this is really an unqualified access. We have to err on the side of producing
+ // false negatives for the sake of usability.
+ if (qmlScope->isInCustomParserParent()) {
+ // We can handle Connections properly
+ if (qmlScope->baseType()
+ && qmlScope->baseType()->internalName() != u"QQmlConnections"_qs)
+ continue;
+ }
+
const auto location = memberAccessBase.m_location;
if (baseIsPrefixed) {