diff --git a/tests/auto/qml/qmllint/data/DeprProp.qml b/tests/auto/qml/qmllint/data/DeprProp.qml new file mode 100644 index 0000000000..39f271902e --- /dev/null +++ b/tests/auto/qml/qmllint/data/DeprProp.qml @@ -0,0 +1,8 @@ +import QtQml + +QtObject { + @Deprecated {} + property int deprecated: 500 + @Deprecated { reason: "Test" } + property int deprecatedReason: 200 +} diff --git a/tests/auto/qml/qmllint/data/deprecatedProperty.qml b/tests/auto/qml/qmllint/data/deprecatedProperty.qml index 539e7abb38..c2edbc4436 100644 --- a/tests/auto/qml/qmllint/data/deprecatedProperty.qml +++ b/tests/auto/qml/qmllint/data/deprecatedProperty.qml @@ -1,5 +1,3 @@ -import QtQml - QtObject { @Deprecated {} property int deprecated: 10 diff --git a/tests/auto/qml/qmllint/data/deprecatedPropertyBinding.qml b/tests/auto/qml/qmllint/data/deprecatedPropertyBinding.qml new file mode 100644 index 0000000000..ba3fbe6024 --- /dev/null +++ b/tests/auto/qml/qmllint/data/deprecatedPropertyBinding.qml @@ -0,0 +1,3 @@ +DeprProp { + deprecated: 200 +} diff --git a/tests/auto/qml/qmllint/data/deprecatedPropertyBindingReason.qml b/tests/auto/qml/qmllint/data/deprecatedPropertyBindingReason.qml new file mode 100644 index 0000000000..543afde5e3 --- /dev/null +++ b/tests/auto/qml/qmllint/data/deprecatedPropertyBindingReason.qml @@ -0,0 +1,3 @@ +DeprProp { + deprecatedReason: 200 +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 5a570fa553..3b15f2f825 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -476,6 +476,16 @@ void TestQmllint::dirtyQmlCode_data() << QStringLiteral("Property \"deprecated\" is deprecated") << QString() << false; + QTest::newRow("Deprecation (Property binding, with reason)") + << QStringLiteral("deprecatedPropertyBindingReason.qml") + << QStringLiteral("Binding on deprecated property \"deprecatedReason\" (Reason: Test)") + << QString() + << false; + QTest::newRow("Deprecation (Property binding, no reason)") + << QStringLiteral("deprecatedPropertyBinding.qml") + << QStringLiteral("Binding on deprecated property \"deprecated\"") + << QString() + << false; QTest::newRow("Deprecation (Type, with reason)") << QStringLiteral("deprecatedTypeReason.qml") << QStringLiteral("Type \"TypeDeprecatedReason\" is deprecated (Reason: Test)") diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index 67d40e8a1d..df53741d62 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -299,6 +299,23 @@ bool FindWarningVisitor::visit(QQmlJS::AST::UiScriptBinding *uisb) ); } + const auto &annotations = property.annotations(); + + const auto deprecationAnn = std::find_if(annotations.cbegin(), annotations.cend(), [](const QQmlJSAnnotation &ann) { return ann.isDeprecation(); }); + + if (deprecationAnn != annotations.cend()) { + const auto deprecation = deprecationAnn->deprecation(); + + QString message = QStringLiteral("Binding on deprecated property \"%1\"") + .arg(property.propertyName()); + + if (!deprecation.reason.isEmpty()) + message.append(QStringLiteral(" (Reason: %1)").arg(deprecation.reason)); + + m_logger.log(message, Log_Deprecation, uisb->firstSourceLocation()); + } + + return true; }