qmllint: Warn about bindings on deprecated properties

qmllint will now warn about bindings on deprecated properties as opposed to only warning when the property itself referenced.

Fixes: QTBUG-92207
Change-Id: I93c54d55e2ab2ca0648f67ac967c792d3ba60844
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Maximilian Goldstein 2021-03-29 13:15:44 +02:00
parent 0ff9db566c
commit 2e85f3492b
6 changed files with 41 additions and 2 deletions

View File

@ -0,0 +1,8 @@
import QtQml
QtObject {
@Deprecated {}
property int deprecated: 500
@Deprecated { reason: "Test" }
property int deprecatedReason: 200
}

View File

@ -1,5 +1,3 @@
import QtQml
QtObject {
@Deprecated {}
property int deprecated: 10

View File

@ -0,0 +1,3 @@
DeprProp {
deprecated: 200
}

View File

@ -0,0 +1,3 @@
DeprProp {
deprecatedReason: 200
}

View File

@ -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)")

View File

@ -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;
}