diff options
author | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-22 16:12:57 +0100 |
---|---|---|
committer | Ulf Hermann <ulf.hermann@qt.io> | 2021-02-24 13:01:48 +0100 |
commit | 7ecd4b6d1f20fd729e9746cf41fe863cd382e42f (patch) | |
tree | a108815d9c009361bfbb0104b97c1bce61ac7ad1 /tools/qmllint | |
parent | 74bf3c8c333c30f4d3b4db31b5cc0b5150a08c88 (diff) |
qmllint: Resolve imported files by qrc path if available
If a file is part of the resource file system, the implicit directory is
also in the resource file system. We can use QQmlJSResourceFileMapper to
figure this out.
Change-Id: I48d86c308c7ec38d9971b84e7f059daa3baf63ee
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint')
-rw-r--r-- | tools/qmllint/findwarnings.cpp | 4 | ||||
-rw-r--r-- | tools/qmllint/main.cpp | 35 |
2 files changed, 30 insertions, 9 deletions
diff --git a/tools/qmllint/findwarnings.cpp b/tools/qmllint/findwarnings.cpp index b23d517d41..e0e1c3831e 100644 --- a/tools/qmllint/findwarnings.cpp +++ b/tools/qmllint/findwarnings.cpp @@ -338,7 +338,9 @@ bool FindWarningVisitor::visit(QQmlJS::AST::IdentifierExpression *idexp) FindWarningVisitor::FindWarningVisitor( QQmlJSImporter *importer, QStringList qmltypesFiles, QString code, QString fileName, bool silent, bool warnUnqualified, bool warnWithStatement, bool warnInheritanceCycle) - : QQmlJSImportVisitor(importer, QFileInfo {fileName}.canonicalPath(), qmltypesFiles), + : QQmlJSImportVisitor(importer, + implicitImportDirectory(fileName, importer->resourceFileMapper()), + qmltypesFiles), m_code(std::move(code)), m_rootId(QLatin1String("<id>")), m_filePath(std::move(fileName)), diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index b41b0dcb3d..3fb9e9c324 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -28,6 +28,8 @@ #include "findwarnings.h" +#include <QtQmlCompiler/private/qqmljsresourcefilemapper_p.h> + #include <QtQml/private/qqmljslexer_p.h> #include <QtQml/private/qqmljsparser_p.h> #include <QtQml/private/qqmljsengine_p.h> @@ -50,7 +52,8 @@ static bool lint_file(const QString &filename, const bool silent, const bool warnUnqualified, const bool warnWithStatement, const bool warnInheritanceCycle, - const QStringList &qmlImportPaths, const QStringList &qmltypesFiles) + const QStringList &qmlImportPaths, const QStringList &qmltypesFiles, + const QString &resourceFile) { QFile file(filename); if (!file.open(QFile::ReadOnly)) { @@ -85,12 +88,20 @@ static bool lint_file(const QString &filename, const bool silent, const bool war } if (success && !isJavaScript) { - auto root = parser.rootNode(); - QQmlJSImporter importer(qmlImportPaths); - FindWarningVisitor v { &importer, qmltypesFiles, code, filename, silent, - warnUnqualified, warnWithStatement, warnInheritanceCycle }; - root->accept(&v); - success = v.check(); + const auto check = [&](QQmlJSResourceFileMapper *mapper) { + QQmlJSImporter importer(qmlImportPaths, mapper); + FindWarningVisitor v { &importer, qmltypesFiles, code, filename, silent, + warnUnqualified, warnWithStatement, warnInheritanceCycle }; + parser.rootNode()->accept(&v); + success = v.check(); + }; + + if (resourceFile.isEmpty()) { + check(nullptr); + } else { + QQmlJSResourceFileMapper mapper({ resourceFile }); + check(&mapper); + } } return success; @@ -124,6 +135,12 @@ int main(int argv, char *argc[]) parser.addOption(disableCheckInheritanceCycle); + QCommandLineOption resourceOption( + { QStringLiteral("resource") }, + QStringLiteral("Look for related files in the given resource file"), + QStringLiteral("resource")); + parser.addOption(resourceOption); + QCommandLineOption qmlImportPathsOption( QStringList() << "I" << "qmldirs", @@ -177,6 +194,8 @@ int main(int argv, char *argc[]) } } + const QString resourceFile = parser.value(resourceOption); + #else bool silent = false; bool warnUnqualified = true; @@ -193,7 +212,7 @@ int main(int argv, char *argc[]) for (const QString &filename : arguments) #endif success &= lint_file(filename, silent, warnUnqualified, warnWithStatement, - warnInheritanceCycle, qmlImportPaths, qmltypesFiles); + warnInheritanceCycle, qmlImportPaths, qmltypesFiles, resourceFile); return success ? 0 : -1; } |