diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2019-08-16 16:44:06 +0200 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2019-08-30 10:34:51 +0200 |
commit | c3fa4a2d39dce9e20c6f0ce93465440d408dac8d (patch) | |
tree | 7b5ea6570b7135abaf8efe01a501ac9167792cd8 | |
parent | 8f5f363ce8aa0cc9a4abe33bd9e21e59fe1b575a (diff) |
qmllint: Consider methods from the current scope as valid IDs
Change-Id: I71e9e2d5b4623938605d7afbfc79ae5c7d4251fc
Reviewed-by: Simon Hausmann <simon.hausmann@qt.io>
-rw-r--r-- | tests/auto/qml/qmllint/data/MethodInItem.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/data/MethodInScope.qml | 5 | ||||
-rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 7 | ||||
-rw-r--r-- | tools/qmllint/findunqualified.cpp | 1 | ||||
-rw-r--r-- | tools/qmllint/scopetree.cpp | 2 |
5 files changed, 19 insertions, 1 deletions
diff --git a/tests/auto/qml/qmllint/data/MethodInItem.qml b/tests/auto/qml/qmllint/data/MethodInItem.qml new file mode 100644 index 0000000000..dbdaf8bcc1 --- /dev/null +++ b/tests/auto/qml/qmllint/data/MethodInItem.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +QtObject { + function doThings() { console.log("things") } +} diff --git a/tests/auto/qml/qmllint/data/MethodInScope.qml b/tests/auto/qml/qmllint/data/MethodInScope.qml new file mode 100644 index 0000000000..7ba0829f61 --- /dev/null +++ b/tests/auto/qml/qmllint/data/MethodInScope.qml @@ -0,0 +1,5 @@ +import QtQml 2.0 + +MethodInItem { + Component.onCompleted: doThings() +} diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index 8233dbebe5..cfcc6bf246 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -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); diff --git a/tools/qmllint/findunqualified.cpp b/tools/qmllint/findunqualified.cpp index 42c74059c3..32eda12052 100644 --- a/tools/qmllint/findunqualified.cpp +++ b/tools/qmllint/findunqualified.cpp @@ -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) { diff --git a/tools/qmllint/scopetree.cpp b/tools/qmllint/scopetree.cpp index 0ba4f9e38e..1e873cca8f 100644 --- a/tools/qmllint/scopetree.cpp +++ b/tools/qmllint/scopetree.cpp @@ -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 |