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:
parent
0ff9db566c
commit
2e85f3492b
|
@ -0,0 +1,8 @@
|
|||
import QtQml
|
||||
|
||||
QtObject {
|
||||
@Deprecated {}
|
||||
property int deprecated: 500
|
||||
@Deprecated { reason: "Test" }
|
||||
property int deprecatedReason: 200
|
||||
}
|
|
@ -1,5 +1,3 @@
|
|||
import QtQml
|
||||
|
||||
QtObject {
|
||||
@Deprecated {}
|
||||
property int deprecated: 10
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
DeprProp {
|
||||
deprecated: 200
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
DeprProp {
|
||||
deprecatedReason: 200
|
||||
}
|
|
@ -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)")
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue