diff options
author | Andrei Golubev <andrei.golubev@qt.io> | 2021-08-18 11:04:34 +0200 |
---|---|---|
committer | Andrei Golubev <andrei.golubev@qt.io> | 2021-08-19 08:33:33 +0200 |
commit | 07f9525f3ef945b7458a956add3c9b7ff9c98123 (patch) | |
tree | 77c9da3765497f457fa227949c7303dc6037bbd8 /tools/qmllint/main.cpp | |
parent | 0a801af5c32cc1928f6b79f934030839de9917d2 (diff) |
Decouple QQmlJSLogger from QQmlImportVisitor
QQmlImportVisitor was accepting ctor paratemeters for the QQmlJSLogger,
creating own logger internally. This seems wrong since in that case we
kind of have separate logger for visitor and type resolver (among other
entities)
On top of this, the import visitor had a silent logging by default
(and the QQmlJSLogger is not silent on the contrary) which in fact hid
some issues that should've been reported by qmllint (but they weren't)
For consistency, the silent logger is still used. And the ultimate fix
would be to use FindWarningsVisitor instead of QQmlJSImportVisitor
as currently we do 2 AST traversals in qmllint
Change-Id: I4c54b76d130e7e8f31c90a148edc1c02f7e86ab8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r-- | tools/qmllint/main.cpp | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index ee16409f4e..3c9d19eb58 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -171,18 +171,23 @@ static bool lint_file(const QString &filename, const bool silent, QJsonArray *js importer.setResourceFileMapper(mapper); - FindWarningVisitor v { &importer, qmltypesFiles, code, - engine.comments(), filename, silent || json }; + QQmlJSLogger logger(filename, code, silent || json); + FindWarningVisitor v { + &importer, + &logger, + qmltypesFiles, + engine.comments(), + }; for (auto it = options.cbegin(); it != options.cend(); ++it) { - v.logger().setCategoryError(it.value().m_category, it.value().m_error); - v.logger().setCategoryLevel(it.value().m_category, it.value().m_level); + logger.setCategoryError(it.value().m_category, it.value().m_error); + logger.setCategoryLevel(it.value().m_category, it.value().m_level); } parser.rootNode()->accept(&v); success = v.check(); - Codegen codegen { &importer, filename, qmltypesFiles, &v.logger(), code }; + Codegen codegen { &importer, filename, qmltypesFiles, &logger, code }; QQmlJSSaveFunction saveFunction = [](const QV4::CompiledData::SaveableUnitPointer &, const QQmlJSAotFunctionMap &, QString *) { return true; }; @@ -191,17 +196,17 @@ static bool lint_file(const QString &filename, const bool silent, QJsonArray *js QLoggingCategory::setFilterRules(u"qt.qml.compiler=false"_qs); - CodegenWarningInterface interface(&v.logger()); + CodegenWarningInterface interface(&logger); qCompileQmlFile(filename, saveFunction, &codegen, &error, true, &interface); - success &= !v.logger().hasWarnings() && !v.logger().hasErrors(); + success &= !logger.hasWarnings() && !logger.hasErrors(); if (json) { - for (const auto &error : v.logger().errors()) + for (const auto &error : logger.errors()) addJsonWarning(error); - for (const auto &warning : v.logger().warnings()) + for (const auto &warning : logger.warnings()) addJsonWarning(warning); - for (const auto &info : v.logger().infos()) + for (const auto &info : logger.infos()) addJsonWarning(info); } }; |