qmllint: Consider methods from the current scope as valid IDs
Change-Id: I71e9e2d5b4623938605d7afbfc79ae5c7d4251fc Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
This commit is contained in:
parent
8f5f363ce8
commit
c3fa4a2d39
|
@ -0,0 +1,5 @@
|
|||
import QtQml 2.0
|
||||
|
||||
QtObject {
|
||||
function doThings() { console.log("things") }
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
import QtQml 2.0
|
||||
|
||||
MethodInItem {
|
||||
Component.onCompleted: doThings()
|
||||
}
|
|
@ -46,6 +46,7 @@ private Q_SLOTS:
|
|||
void catchIdentifierNoFalsePositive();
|
||||
void testUnmatchedSignalHandler();
|
||||
void uiQml();
|
||||
void methodInScope();
|
||||
|
||||
private:
|
||||
QString runQmllint(const QString &fileToLint, bool shouldSucceed);
|
||||
|
@ -143,6 +144,12 @@ void TestQmllint::uiQml()
|
|||
QVERIFY(output.isEmpty());
|
||||
}
|
||||
|
||||
void TestQmllint::methodInScope()
|
||||
{
|
||||
const QString output = runQmllint("MethodInScope.qml", true);
|
||||
QVERIFY(output.isEmpty());
|
||||
}
|
||||
|
||||
void TestQmllint::test()
|
||||
{
|
||||
QFETCH(QString, filename);
|
||||
|
|
|
@ -274,6 +274,7 @@ FindUnqualifiedIDVisitor::localQmlFile2FakeMetaObject(QString filePath)
|
|||
auto sourceElement = static_cast<UiSourceElement *>(initMembers->member);
|
||||
if (FunctionExpression *fexpr = sourceElement->sourceElement->asFunctionDefinition()) {
|
||||
LanguageUtils::FakeMetaMethod method;
|
||||
method.setMethodName(fexpr->name.toString());
|
||||
method.setMethodType(LanguageUtils::FakeMetaMethod::Method);
|
||||
FormalParameterList *parameters = fexpr->formals;
|
||||
while (parameters) {
|
||||
|
|
|
@ -226,7 +226,7 @@ QMap<QString, LanguageUtils::FakeMetaMethod>const &ScopeTree::methods() const
|
|||
bool ScopeTree::isIdInCurrentQMlScopes(QString id) const
|
||||
{
|
||||
auto qmlScope = getCurrentQMLScope();
|
||||
return qmlScope->m_currentScopeQMLIdentifiers.contains(id);
|
||||
return qmlScope->m_currentScopeQMLIdentifiers.contains(id) || qmlScope->m_methods.contains(id);
|
||||
}
|
||||
|
||||
bool ScopeTree::isIdInCurrentJSScopes(QString id) const
|
||||
|
|
Loading…
Reference in New Issue