diff options
| author | Ulf Hermann <ulf.hermann@qt.io> | 2024-09-03 15:51:01 +0200 |
|---|---|---|
| committer | Ulf Hermann <ulf.hermann@qt.io> | 2024-09-04 23:29:40 +0200 |
| commit | ebd8b856d9d342562dedff26b2bef4bd1bca699a (patch) | |
| tree | c36c4dec0dfb7d2278cddf70a0c529c297294d1f | |
| parent | ae7419479a4a7e7777b0ce4272b8653c68a8d447 (diff) | |
qmllint: Make hint for missing types more precise
Usually, if some type is not found, that's due to a dependency or an
import missing. A missing import path is much less common.
Pick-to: 6.8
Change-Id: I33e797b037315b44b9d573f221b4d16bdc88ce17
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
| -rw-r--r-- | src/qmlcompiler/qqmljsimportvisitor.cpp | 18 | ||||
| -rw-r--r-- | tests/auto/qml/qmllint/tst_qmllint.cpp | 43 |
2 files changed, 40 insertions, 21 deletions
diff --git a/src/qmlcompiler/qqmljsimportvisitor.cpp b/src/qmlcompiler/qqmljsimportvisitor.cpp index df715976ab..edc65fc6fe 100644 --- a/src/qmlcompiler/qqmljsimportvisitor.cpp +++ b/src/qmlcompiler/qqmljsimportvisitor.cpp @@ -34,6 +34,11 @@ using namespace Qt::StringLiterals; using namespace QQmlJS::AST; +static const QLatin1StringView wasNotFound + = "was not found."_L1; +static const QLatin1StringView didYouAddAllImports + = "Did you add all imports and dependencies?"_L1; + /*! \internal Returns if assigning \a assignedType to \a property would require an @@ -659,8 +664,7 @@ void QQmlJSImportVisitor::processPropertyTypes() property.setType(propertyType); type.scope->addOwnProperty(property); } else { - m_logger->log(property.typeName() - + QStringLiteral(" was not found. Did you add all import paths?"), + m_logger->log(property.typeName() + ' '_L1 + wasNotFound + ' '_L1 + didYouAddAllImports, qmlImport, type.location); } } @@ -1051,10 +1055,10 @@ void QQmlJSImportVisitor::checkSignal( auto type = p.type(); if (!type) { m_logger->log( - QStringLiteral( - "Type %1 of parameter %2 in signal%3 was not found, but is " - "required to compile %4. Did you add all import paths?") - .arg(p.typeName(), p.name(), signalName(), handlerName), + "Type %1 of parameter %2 in signal %3 %4, but is required to compile " + "%4. %5"_L1.arg( + p.typeName(), p.name(), signalName(), wasNotFound, + handlerName, didYouAddAllImports), qmlSignalParameters, location); continue; } @@ -1200,7 +1204,7 @@ void QQmlJSImportVisitor::breakInheritanceCycles(const QQmlJSScope::Ptr &origina m_logger->log(error, qmlImport, scope->sourceLocation(), true, true); } else if (!name.isEmpty()) { m_logger->log( - name + QStringLiteral(" was not found. Did you add all import paths?"), + name + ' '_L1 + wasNotFound + ' '_L1 + didYouAddAllImports, qmlImport, scope->sourceLocation(), true, true, QQmlJSUtils::didYouMean(scope->baseTypeName(), m_rootScopeImports.types().keys(), diff --git a/tests/auto/qml/qmllint/tst_qmllint.cpp b/tests/auto/qml/qmllint/tst_qmllint.cpp index f04faddfe1..2a3528fc52 100644 --- a/tests/auto/qml/qmllint/tst_qmllint.cpp +++ b/tests/auto/qml/qmllint/tst_qmllint.cpp @@ -306,12 +306,20 @@ void TestQmllint::testUnknownCausesFail() { runTest("unknownElement.qml", Result { { Message { - QStringLiteral("Unknown was not found. Did you add all import paths?"), 4, 5, - QtWarningMsg } } }); + QStringLiteral( + "Unknown was not found. " + "Did you add all imports and dependencies?"), + 4, 5, + QtWarningMsg + } } }); runTest("TypeWithUnknownPropertyType.qml", Result { { Message { - QStringLiteral("Something was not found. Did you add all import paths?"), 4, 5, - QtWarningMsg } } }); + QStringLiteral( + "Something was not found. " + "Did you add all imports and dependencies?"), + 4, 5, + QtWarningMsg + } } }); } void TestQmllint::directoryPassedAsQmlTypesFile() @@ -334,8 +342,11 @@ void TestQmllint::oldQmltypes() Message { QStringLiteral( "Revision 0 corresponds to version 0.0; it should be 1.0.") }, }, - { Message { QStringLiteral( - "QQuickItem was not found. Did you add all import paths?") } } }); + { + Message { QStringLiteral("QQuickItem was not found. " + "Did you add all imports and dependencies?") + } + } }); } void TestQmllint::qmltypes_data() @@ -597,8 +608,9 @@ void TestQmllint::dirtyQmlCode_data() QTest::newRow("badQmldirImportAndDepend") << QStringLiteral("qmldirImportAndDepend/bad.qml") << Result { { Message { - QStringLiteral("Item was not found. Did you add all import paths?"), 3, - 1 } } }; + QStringLiteral("Item was not found. " + "Did you add all imports and dependencies?"), + 3, 1 } } }; QTest::newRow("javascriptMethodsInModule") << QStringLiteral("javascriptMethodsInModuleBad.qml") << Result { { Message { @@ -761,7 +773,7 @@ void TestQmllint::dirtyQmlCode_data() QTest::newRow("DefaultPropertyLookupInUnknownType") << QStringLiteral("unknownParentDefaultPropertyCheck.qml") << Result { { Message { QStringLiteral( - "Alien was not found. Did you add all import paths?") } } }; + "Alien was not found. Did you add all imports and dependencies?") } } }; QTest::newRow("InvalidImport") << QStringLiteral("invalidImport.qml") << Result { { Message { QStringLiteral( @@ -873,7 +885,9 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", QTest::newRow("unresolvedType") << QStringLiteral("unresolvedType.qml") << Result { { Message { QStringLiteral( - "UnresolvedType was not found. Did you add all import paths?") } }, + "UnresolvedType was not found. " + "Did you add all imports and dependencies?") + } }, { Message { QStringLiteral("incompatible type") } } }; QTest::newRow("invalidInterceptor") << QStringLiteral("invalidInterceptor.qml") @@ -1037,9 +1051,9 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", QTest::newRow("didYouMean(component)") << QStringLiteral("didYouMeanComponent.qml") << Result { { Message { QStringLiteral( - "Itym was not found. Did you add all import paths?") }, - {}, - { Message { QStringLiteral("Item") } } } }; + "Itym was not found. Did you add all imports and dependencies?") + }, {}, + { Message { QStringLiteral("Item") } } } }; QTest::newRow("didYouMean(enum)") << QStringLiteral("didYouMeanEnum.qml") << Result { { Message { QStringLiteral( @@ -1095,7 +1109,8 @@ expression: \${expr} \${expr} \\\${expr} \\\${expr}`)", QTest::newRow("assignNonExistingTypeToVarProp") << QStringLiteral("assignNonExistingTypeToVarProp.qml") << Result { { Message { QStringLiteral( - "NonExistingType was not found. Did you add all import paths?") } } }; + "NonExistingType was not found. Did you add all imports and dependencies?") + } } }; QTest::newRow("unboundComponents") << QStringLiteral("unboundComponents.qml") << Result { { |
