From 3dff3ce1bd38fff8103d565590120d5f746c180a Mon Sep 17 00:00:00 2001 From: Ulf Hermann Date: Tue, 30 Jan 2024 16:13:29 +0100 Subject: [PATCH] qmllint: Complain about "target" when complaining about PropertyChanges You should remove the binding on the target property, too, after rephrasing the binding. Pick-to: 6.6 6.5 Fixes: QTBUG-113695 Change-Id: I917f506c932605ae5851ae09f4383af59a3cae1e Reviewed-by: Fabian Kosmale (cherry picked from commit 7bc52d660c692bf727c1741e1b9981e5b337f45f) Reviewed-by: Qt Cherry-pick Bot --- src/plugins/qmllint/quick/quicklintplugin.cpp | 11 ++++++++++- tests/auto/qml/qmllint/tst_qmllint.cpp | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/plugins/qmllint/quick/quicklintplugin.cpp b/src/plugins/qmllint/quick/quicklintplugin.cpp index 5452b84dfb..7735a8e596 100644 --- a/src/plugins/qmllint/quick/quicklintplugin.cpp +++ b/src/plugins/qmllint/quick/quicklintplugin.cpp @@ -750,11 +750,13 @@ void PropertyChangesValidatorPass::run(const QQmlSA::Element &element) return; QString targetId = u""_s; - const QString targetBinding = sourceCode(target.value().sourceLocation()); + const auto targetLocation = target.value().sourceLocation(); + const QString targetBinding = sourceCode(targetLocation); const QQmlSA::Element targetElement = resolveIdToElement(targetBinding, element); if (!targetElement.isNull()) targetId = targetBinding; + bool hadCustomParsedBindings = false; for (auto it = bindings.constBegin(); it != bindings.constEnd(); ++it) { const auto &propertyName = it.key(); const auto &propertyBinding = it.value(); @@ -773,11 +775,18 @@ void PropertyChangesValidatorPass::run(const QQmlSA::Element &element) if (binding.length() > 16) binding = binding.left(13) + "..."_L1; + hadCustomParsedBindings = true; emitWarning("Property \"%1\" is custom-parsed in PropertyChanges. " "You should phrase this binding as \"%2.%1: %3\""_L1.arg(propertyName, targetId, binding), quickPropertyChangesParsed, bindingLocation); } + + if (hadCustomParsedBindings && !targetElement.isNull()) { + emitWarning("You should remove any bindings on the \"target\" property and avoid " + "custom-parsed bindings in PropertyChanges.", + quickPropertyChangesParsed, targetLocation); + } } QT_END_NAMESPACE diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 3ab57903d6..98efac11a6 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -2058,6 +2058,11 @@ void TestQmllint::quickPlugin() "You should phrase this binding as \"foo.myColor: Qt.rgba(0.5, ...\""_s, 12, 30 }, + Message { + u"You should remove any bindings on the \"target\" property and avoid " + "custom-parsed bindings in PropertyChanges."_s, + 11, 29 + }, Message { u"Unknown property \"notThere\" in PropertyChanges."_s, 13, 31