qmllint: Consider attached properties

We cannot figure out who attached properties to what, therefore we
consider any uppercase property we cannot locate as a potential attached
property.

Change-Id: I60508b9e4e038a51b87c56edf0796ac492aa3fa0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Ulf Hermann 2019-11-15 17:42:18 +01:00
parent 01b865411d
commit d31bb553b5
3 changed files with 17 additions and 0 deletions

View File

@ -0,0 +1,6 @@
import QtQml 2.0
QtObject {
id: self
property var foo: self.Component.completed
}

View File

@ -191,6 +191,7 @@ void TestQmllint::cleanQmlCode_data()
QTest::newRow("goodAlias") << QStringLiteral("goodAlias.qml");
QTest::newRow("goodParent") << QStringLiteral("goodParent.qml");
QTest::newRow("goodTypeAssertion") << QStringLiteral("goodTypeAssertion.qml");
QTest::newRow("AttachedProps") << QStringLiteral("AttachedProps.qml");
}
void TestQmllint::cleanQmlCode()

View File

@ -230,6 +230,16 @@ bool ScopeTree::checkMemberAccess(
type = types.value(type->superclassName());
}
if (access->m_name.front().isUpper() && scope->scopeType() == ScopeType::QMLScope) {
// may be an attached type
const auto it = types.find(access->m_name);
if (it != types.end() && !(*it)->attachedTypeName().isEmpty()) {
const auto attached = types.find((*it)->attachedTypeName());
if (attached != types.end())
return checkMemberAccess(code, access.get(), attached->get(), types, colorOut);
}
}
colorOut.write("Warning: ", Warning);
colorOut.write(QString::fromLatin1(
"Property \"%1\" not found on type \"%2\" at %3:%4\n")