diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-01-30 16:13:29 +0100 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-02-01 19:30:23 +0100 |
| commit | c6416101b210ae13ad8525a6e6ac6a735434bfe5 (patch) | |
| tree | 86b2bda4b8f50e579a0c4f2ec76162a31958995c | |
| parent | 912886afe4d58130eb218342843fe85e15128f17 (diff) | |
qmllint: Complain about "target" when complaining about PropertyChanges
You should remove the binding on the target property, too, after
rephrasing the binding.
Fixes: QTBUG-113695
Change-Id: I917f506c932605ae5851ae09f4383af59a3cae1e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
(cherry picked from commit 7bc52d660c692bf727c1741e1b9981e5b337f45f)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 3dff3ce1bd38fff8103d565590120d5f746c180a)
(cherry picked from commit c753d52d8ed56f3d49b0333a99dd47d57fdad8a1)
| -rw-r--r-- | src/plugins/qmllint/quick/quicklintplugin.cpp | 11 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 5 |
2 files changed, 15 insertions, 1 deletions
diff --git a/src/plugins/qmllint/quick/quicklintplugin.cpp b/src/plugins/qmllint/quick/quicklintplugin.cpp index b026fd96a1..afed093269 100644 --- a/src/plugins/qmllint/quick/quicklintplugin.cpp +++ b/src/plugins/qmllint/quick/quicklintplugin.cpp @@ -761,11 +761,13 @@ void PropertyChangesValidatorPass::run(const QQmlSA::Element &element) return; QString targetId = u"<id>"_s; - const QString targetBinding = sourceCode(target->sourceLocation()); + const auto targetLocation = target->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.begin(), end = bindings.end(); it != end; ++it) { const QString name = it->propertyName(); if (element->hasProperty(name)) @@ -783,12 +785,19 @@ 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(name, 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 8b8c9c2d2f..e6354a39cd 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -2025,6 +2025,11 @@ void TestQmllint::quickPlugin() 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 } |
