diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-04-14 13:18:02 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-04-19 10:15:13 +0200 |
commit | 63c906ddc861d9c2116140c43c506823fc115817 (patch) | |
tree | 77a8845c0c9d8542eb70bc04418d9ced0ab9267c /tools | |
parent | 9c6b1d7fb6eb627655f891fd406e8381de25281d (diff) |
qmllint: Warn about deprecated functions
Now qmllint will also warn when functions have a Deprecated annotation which previously only applied to properties and elements.
Task-number: QTBUG-84895
Fixes: QTBUG-79857
Change-Id: Ie1436822dc06bfd1ee4305a8468900409c3f8b0a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools')
-rw-r--r-- | tools/qmllint/checkidentifiers.cpp | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp index e2ac8981f5..1e889926a1 100644 --- a/tools/qmllint/checkidentifiers.cpp +++ b/tools/qmllint/checkidentifiers.cpp @@ -299,6 +299,27 @@ void CheckIdentifiers::operator()( auto qmlScope = QQmlJSScope::findCurrentQMLScope(currentScope); if (qmlScope->hasMethod(memberAccessBase.m_name)) { // a property of a JavaScript function, or a method + auto methods = qmlScope->methods(memberAccessBase.m_name); + const QQmlJSMetaMethod &method = methods.constFirst(); + const auto &annotations = method.annotations(); + auto deprecationAnn = std::find_if(annotations.constBegin(), annotations.constEnd(), [](const QQmlJSAnnotation& annotation) { + return annotation.isDeprecation(); + }); + + // Once we encountered one possible method that is not deprecated, + // we can assume that the one beyond that is not what was being referenced + if (deprecationAnn == annotations.constEnd()) + continue; + + QQQmlJSDeprecation deprecation = deprecationAnn->deprecation(); + + QString message = QStringLiteral("Method \"%1(%2)\" is deprecated") + .arg(memberAccessBase.m_name, method.parameterNames().join(QStringLiteral(", "))); + + if (!deprecation.reason.isEmpty()) + message.append(QStringLiteral(" (Reason: %1)").arg(deprecation.reason)); + + m_logger->log(message, Log_Deprecation, memberAccessBase.m_location); continue; } |