2022-05-13 13:12:05 +00:00
|
|
|
// Copyright (C) 2022 The Qt Company Ltd.
|
|
|
|
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
|
2021-03-25 14:34:42 +00:00
|
|
|
|
|
|
|
#include "qqmljslogger_p.h"
|
|
|
|
|
2022-02-24 09:28:52 +00:00
|
|
|
#include <QtCore/qfile.h>
|
|
|
|
#include <QtCore/qfileinfo.h>
|
|
|
|
|
2021-11-22 12:41:14 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2022-03-21 09:21:18 +00:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2021-03-30 10:58:26 +00:00
|
|
|
const QMap<QString, QQmlJSLogger::Option> &QQmlJSLogger::options() {
|
|
|
|
static QMap<QString, QQmlJSLogger::Option> optionsMap = {
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("required"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Required, QStringLiteral("RequiredProperty"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about required properties"), QtWarningMsg) },
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("alias"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Alias, QStringLiteral("PropertyAlias"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about alias errors"), QtWarningMsg) },
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("import"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Import, QStringLiteral("ImportFailure"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about failing imports and deprecated qmltypes"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("with"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_WithStatement, QStringLiteral("WithStatement"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about with statements as they can cause false "
|
|
|
|
"positives when checking for unqualified access"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("inheritance-cycle"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_InheritanceCycle, QStringLiteral("InheritanceCycle"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about inheritance cycles"), QtWarningMsg) },
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("deprecated"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Deprecation, QStringLiteral("Deprecated"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about deprecated properties and types"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("signal"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Signal, QStringLiteral("BadSignalHandler"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about bad signal handler parameters"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("type"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Type, QStringLiteral("TypeError"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about unresolvable types and type mismatches"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("property"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_Property, QStringLiteral("UnknownProperty"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about unknown properties"), QtWarningMsg) },
|
2021-11-26 11:42:03 +00:00
|
|
|
{ QStringLiteral("deferred-property-id"),
|
|
|
|
QQmlJSLogger::Option(
|
|
|
|
Log_DeferredPropertyId, QStringLiteral("DeferredPropertyId"),
|
|
|
|
QStringLiteral(
|
|
|
|
"Warn about making deferred properties immediate by giving them an id."),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QtWarningMsg) },
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("unqualified"),
|
|
|
|
QQmlJSLogger::Option(
|
2021-05-12 16:32:57 +00:00
|
|
|
Log_UnqualifiedAccess, QStringLiteral("UnqualifiedAccess"),
|
2021-04-19 14:54:45 +00:00
|
|
|
QStringLiteral("Warn about unqualified identifiers and how to fix them"),
|
|
|
|
QtWarningMsg) },
|
|
|
|
{ QStringLiteral("unused-imports"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_UnusedImport, QStringLiteral("UnusedImports"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about unused imports"), QtInfoMsg) },
|
2021-04-19 14:54:45 +00:00
|
|
|
{ QStringLiteral("multiline-strings"),
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlJSLogger::Option(Log_MultilineString, QStringLiteral("MultilineStrings"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about multiline strings"), QtInfoMsg) },
|
2021-07-05 10:48:49 +00:00
|
|
|
{ QStringLiteral("compiler"),
|
|
|
|
QQmlJSLogger::Option(Log_Compiler, QStringLiteral("CompilerWarnings"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QStringLiteral("Warn about compiler issues"), QtCriticalMsg, true) },
|
2021-09-23 10:18:17 +00:00
|
|
|
{ QStringLiteral("controls-sanity"),
|
|
|
|
QQmlJSLogger::Option(
|
|
|
|
Log_ControlsSanity, QStringLiteral("ControlsSanity"),
|
2021-11-26 11:42:03 +00:00
|
|
|
QStringLiteral("Performance checks used for QuickControl's implementation"),
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QtCriticalMsg, true) },
|
2021-09-22 16:57:27 +00:00
|
|
|
{ QStringLiteral("multiple-attached-objects"),
|
|
|
|
QQmlJSLogger::Option(
|
|
|
|
Log_AttachedPropertyReuse, QStringLiteral("AttachedPropertyReuse"),
|
|
|
|
QStringLiteral("Warn if attached types from parent components aren't reused"),
|
qmlcompiler: Implement structured QML static analysis
This patch adds the qqmlsa "framework", which is meant as a starting
point for a more structured, extendible static analysis for QML.
While qmllint (or rather, the QQmlJSImportVisitor used by it) can
already do quite a few checks internally, it is hard to extend.
Moreover, the checks there are interspersed with parsing code, and might
run before all types are resolved. We also do not want to add check that
are specific to QtQuick, Controls, Quick3D... into the core QtQml
module. This poses quite a few challenges: For instance, the color in
QML resolver depends on QtQuick/QtGui to check whether a string is
actually a color.
To overcome the issues mentioned above, we introduce the concept of
analysis passes, and a PassManger class. Passes can come in two shapes
currently:
- PropertyPasses run on each property that has a binding assigned to it
- ElementPasses run on each (sub-)object instantiated in the file
A property can have multiple bindings assigned to it (due to e.g.
Interceptors, but also for list properties). Therefore we pass a list of
them to the ElementPass.
Passes which only want to handle the "normal" case of one binding per
property can use SimpleElementPass, which for now just takes the first
property in the list.
Passes have a pure virtual run function, in which the actual work is
done. They also have a filter function, which in the default
implementation simply returns true, which means that the pass will run.
The filter function is there to make writing passes a bit more
structured, by separating the "do I need to analyze this" question from
the actual analysis part.
To solve the issue of library dependencies, we expose a plugin interface
that then returns passes to be run based on the root component.
Then, user can create a plugin implementing the interface,
which we will load the plugins from a known location, and register all
of them. This will be implemented in the next patch in this set.
Limitations:
- The current passes cannot touch the IR, and thus cannot
really analyze what happens in script binding.
- (inline) components are currently badly handled
- QQmlJSScope has various issuse with grouped properties
Fixes: QTBUG-101604
Original-patch-by: Fabian Kosmale <fabian.kosmale@qt.io>
Change-Id: Ic96259a947fbb17f79aa58ca613c8d0905a9a74c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-16 12:18:41 +00:00
|
|
|
QtCriticalMsg, true) },
|
|
|
|
{ QStringLiteral("plugin"),
|
|
|
|
QQmlJSLogger::Option(Log_Plugin, QStringLiteral("LintPluginWarnings"),
|
|
|
|
QStringLiteral("Warn if a qmllint plugin finds an issue"),
|
2022-03-16 12:19:54 +00:00
|
|
|
QtWarningMsg) }
|
2021-04-19 14:54:45 +00:00
|
|
|
};
|
2021-03-30 10:58:26 +00:00
|
|
|
|
|
|
|
return optionsMap;
|
|
|
|
}
|
|
|
|
|
2021-11-18 13:26:29 +00:00
|
|
|
QQmlJSLogger::QQmlJSLogger()
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
2021-03-30 10:58:26 +00:00
|
|
|
const auto &opt = options();
|
|
|
|
for (auto it = opt.cbegin(); it != opt.cend(); ++it) {
|
|
|
|
m_categoryLevels[it.value().m_category] = it.value().m_level;
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
m_categoryIgnored[it.value().m_category] = it.value().m_ignored;
|
2021-03-30 10:58:26 +00:00
|
|
|
}
|
|
|
|
|
2021-05-11 15:36:08 +00:00
|
|
|
// These have to be set up manually since we don't expose it as an option
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
m_categoryLevels[Log_RecursionDepthError] = QtCriticalMsg;
|
|
|
|
m_categoryLevels[Log_Syntax] = QtWarningMsg; // TODO: because we usually report it as a warning!
|
|
|
|
m_categoryLevels[Log_SyntaxIdQuotation] = QtWarningMsg;
|
|
|
|
m_categoryLevels[Log_SyntaxDuplicateIds] = QtCriticalMsg;
|
2021-03-25 14:34:42 +00:00
|
|
|
|
|
|
|
// setup color output
|
|
|
|
m_output.insertMapping(QtCriticalMsg, QColorOutput::RedForeground);
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
m_output.insertMapping(QtWarningMsg, QColorOutput::PurpleForeground); // Yellow?
|
2021-03-25 14:34:42 +00:00
|
|
|
m_output.insertMapping(QtInfoMsg, QColorOutput::BlueForeground);
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
m_output.insertMapping(QtDebugMsg, QColorOutput::GreenForeground); // None?
|
2021-03-25 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 15:30:42 +00:00
|
|
|
static bool isMsgTypeLess(QtMsgType a, QtMsgType b)
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
2021-07-01 15:30:42 +00:00
|
|
|
static QHash<QtMsgType, int> level = { { QtDebugMsg, 0 },
|
|
|
|
{ QtInfoMsg, 1 },
|
|
|
|
{ QtWarningMsg, 2 },
|
|
|
|
{ QtCriticalMsg, 3 },
|
|
|
|
{ QtFatalMsg, 4 } };
|
|
|
|
return level[a] < level[b];
|
|
|
|
}
|
|
|
|
|
|
|
|
void QQmlJSLogger::log(const QString &message, QQmlJSLoggerCategory category,
|
|
|
|
const QQmlJS::SourceLocation &srcLocation, QtMsgType type, bool showContext,
|
2022-02-24 09:28:52 +00:00
|
|
|
bool showFileName, const std::optional<FixSuggestion> &suggestion,
|
|
|
|
const QString overrideFileName)
|
2021-07-01 15:30:42 +00:00
|
|
|
{
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
if (isCategoryIgnored(category))
|
2021-03-25 14:34:42 +00:00
|
|
|
return;
|
|
|
|
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
// Note: assume \a type is the type we should prefer for logging
|
|
|
|
|
2021-05-27 12:32:43 +00:00
|
|
|
if (srcLocation.isValid() && m_ignoredWarnings[srcLocation.startLine].contains(category))
|
|
|
|
return;
|
|
|
|
|
2021-03-25 14:34:42 +00:00
|
|
|
QString prefix;
|
|
|
|
|
2022-02-24 09:28:52 +00:00
|
|
|
if ((!overrideFileName.isEmpty() || !m_fileName.isEmpty()) && showFileName)
|
|
|
|
prefix =
|
|
|
|
(!overrideFileName.isEmpty() ? overrideFileName : m_fileName) + QStringLiteral(":");
|
2021-03-25 14:34:42 +00:00
|
|
|
|
|
|
|
if (srcLocation.isValid())
|
|
|
|
prefix += QStringLiteral("%1:%2:").arg(srcLocation.startLine).arg(srcLocation.startColumn);
|
|
|
|
|
|
|
|
if (!prefix.isEmpty())
|
|
|
|
prefix.append(QLatin1Char(' '));
|
|
|
|
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
// Note: we do the clamping to [Info, Critical] range since our logger only
|
|
|
|
// supports 3 categories
|
|
|
|
type = std::clamp(type, QtInfoMsg, QtCriticalMsg, isMsgTypeLess);
|
2021-07-01 15:30:42 +00:00
|
|
|
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
// Note: since we clamped our \a type, the output message is not printed
|
|
|
|
// exactly like it was requested, bear with us
|
|
|
|
m_output.writePrefixedMessage(prefix + message, type);
|
2021-03-25 14:34:42 +00:00
|
|
|
|
2021-12-07 17:48:08 +00:00
|
|
|
Message diagMsg;
|
2021-03-25 14:34:42 +00:00
|
|
|
diagMsg.message = message;
|
|
|
|
diagMsg.loc = srcLocation;
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
diagMsg.type = type;
|
2021-12-07 17:48:08 +00:00
|
|
|
diagMsg.fixSuggestion = suggestion;
|
2021-03-25 14:34:42 +00:00
|
|
|
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
switch (type) {
|
2021-03-25 14:34:42 +00:00
|
|
|
case QtWarningMsg: m_warnings.push_back(diagMsg); break;
|
|
|
|
case QtCriticalMsg: m_errors.push_back(diagMsg); break;
|
|
|
|
case QtInfoMsg: m_infos.push_back(diagMsg); break;
|
|
|
|
default: break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (srcLocation.isValid() && !m_code.isEmpty() && showContext)
|
2022-02-24 09:28:52 +00:00
|
|
|
printContext(overrideFileName, srcLocation);
|
2021-03-25 14:34:42 +00:00
|
|
|
|
2021-12-07 17:48:08 +00:00
|
|
|
if (suggestion.has_value())
|
|
|
|
printFix(suggestion.value());
|
2021-07-01 11:55:11 +00:00
|
|
|
}
|
|
|
|
|
2021-07-01 15:30:42 +00:00
|
|
|
void QQmlJSLogger::processMessages(const QList<QQmlJS::DiagnosticMessage> &messages,
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
QQmlJSLoggerCategory category)
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
if (messages.isEmpty() || isCategoryIgnored(category))
|
2021-03-30 08:16:03 +00:00
|
|
|
return;
|
|
|
|
|
|
|
|
m_output.write(QStringLiteral("---\n"));
|
|
|
|
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
// TODO: we should instead respect message's category here (potentially, it
|
|
|
|
// should hold a category instead of type)
|
2021-03-25 14:34:42 +00:00
|
|
|
for (const QQmlJS::DiagnosticMessage &message : messages)
|
Redesign QQmlJSLogger internals
High-level goal: be able to reuse existing infrastructure
"as is" to configure semantic analysis categories in tools
(qmllint, qmltc, qmlsc, etc.)
To achieve that, simplify the logging to always "log"
something, without explicitly specifying the severity. The
severity is now baked into the category (and we can extend
those to cover different cases)
One slight deviation is the cache generation which likes
to do its own thing at present. Provide a "forced logging"
option where we can specify which severify we want. The
hope is that this gets removed at some point
Particular list of (noteworthy) changes:
* No more "thresholding" by the level (this is rarely needed
and is actually questionable). Instead, we can ignore a
particular category explicitly
* Category levels are repurposed as category severities
(at least from the high-level picture that always should've
been this way)
* log{Warning,Info,Critical} removed. We use category severity
instead
* "category error" makes zero sense so removed: if our severity
is:
- QtWarningMsg (qmllint), it is already an "error"
- QtCriticalMsg (compilers), it is already an "error"
* Align m_output and m_{infos,warnings,errors} stored information
* Accept the fact that we don't support QtDebugMsg and QtFatalMsg
* Additional categories added to cover for places where the same
category would be both an error and not an error
Task-number: QTBUG-100052
Change-Id: I3cd5d17d58be204f48428877bed053f756ac40a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-02-03 12:45:18 +00:00
|
|
|
log(message.message, category, QQmlJS::SourceLocation(), false, false);
|
2021-03-30 08:16:03 +00:00
|
|
|
|
|
|
|
m_output.write(QStringLiteral("---\n\n"));
|
2021-03-25 14:34:42 +00:00
|
|
|
}
|
|
|
|
|
2022-02-24 09:28:52 +00:00
|
|
|
void QQmlJSLogger::printContext(const QString &overrideFileName,
|
|
|
|
const QQmlJS::SourceLocation &location)
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
2022-02-24 09:28:52 +00:00
|
|
|
QString code = m_code;
|
|
|
|
|
|
|
|
if (!overrideFileName.isEmpty() && overrideFileName != QFileInfo(m_fileName).absolutePath()) {
|
|
|
|
QFile file(overrideFileName);
|
|
|
|
const bool success = file.open(QFile::ReadOnly);
|
|
|
|
Q_ASSERT(success);
|
|
|
|
code = QString::fromUtf8(file.readAll());
|
|
|
|
}
|
|
|
|
|
|
|
|
IssueLocationWithContext issueLocationWithContext { code, location };
|
2021-03-25 14:34:42 +00:00
|
|
|
if (const QStringView beforeText = issueLocationWithContext.beforeText(); !beforeText.isEmpty())
|
|
|
|
m_output.write(beforeText);
|
2021-04-19 14:54:45 +00:00
|
|
|
|
|
|
|
bool locationMultiline = issueLocationWithContext.issueText().contains(QLatin1Char('\n'));
|
|
|
|
|
2021-07-05 10:48:49 +00:00
|
|
|
if (!issueLocationWithContext.issueText().isEmpty())
|
|
|
|
m_output.write(issueLocationWithContext.issueText().toString(), QtCriticalMsg);
|
2021-08-13 07:44:42 +00:00
|
|
|
m_output.write(issueLocationWithContext.afterText().toString() + QLatin1Char('\n'));
|
2021-04-19 14:54:45 +00:00
|
|
|
|
|
|
|
// Do not draw location indicator for multiline locations
|
|
|
|
if (locationMultiline)
|
|
|
|
return;
|
|
|
|
|
2021-03-25 14:34:42 +00:00
|
|
|
int tabCount = issueLocationWithContext.beforeText().count(QLatin1Char('\t'));
|
2021-07-05 10:48:49 +00:00
|
|
|
int locationLength = location.length == 0 ? 1 : location.length;
|
|
|
|
m_output.write(QString::fromLatin1(" ").repeated(issueLocationWithContext.beforeText().length()
|
|
|
|
- tabCount)
|
|
|
|
+ QString::fromLatin1("\t").repeated(tabCount)
|
|
|
|
+ QString::fromLatin1("^").repeated(locationLength) + QLatin1Char('\n'));
|
2021-03-25 14:34:42 +00:00
|
|
|
}
|
2021-07-01 11:55:11 +00:00
|
|
|
|
|
|
|
void QQmlJSLogger::printFix(const FixSuggestion &fix)
|
|
|
|
{
|
2022-02-24 09:28:52 +00:00
|
|
|
const QString currentFileAbsPath = QFileInfo(m_fileName).absolutePath();
|
|
|
|
QString code = m_code;
|
|
|
|
QString currentFile;
|
2021-07-01 11:55:11 +00:00
|
|
|
for (const auto &fixItem : fix.fixes) {
|
2021-11-23 09:39:28 +00:00
|
|
|
m_output.writePrefixedMessage(fixItem.message, QtInfoMsg);
|
2021-07-01 11:55:11 +00:00
|
|
|
|
|
|
|
if (!fixItem.cutLocation.isValid())
|
|
|
|
continue;
|
|
|
|
|
2022-02-24 09:28:52 +00:00
|
|
|
if (fixItem.fileName == currentFile) {
|
|
|
|
// Nothing to do in this case, we've already read the code
|
|
|
|
} else if (fixItem.fileName.isEmpty() || fixItem.fileName == currentFileAbsPath) {
|
|
|
|
code = m_code;
|
|
|
|
} else {
|
|
|
|
QFile file(fixItem.fileName);
|
|
|
|
const bool success = file.open(QFile::ReadOnly);
|
|
|
|
Q_ASSERT(success);
|
|
|
|
code = QString::fromUtf8(file.readAll());
|
|
|
|
currentFile = fixItem.fileName;
|
|
|
|
}
|
|
|
|
|
|
|
|
IssueLocationWithContext issueLocationWithContext { code, fixItem.cutLocation };
|
2021-07-01 11:55:11 +00:00
|
|
|
|
|
|
|
if (const QStringView beforeText = issueLocationWithContext.beforeText();
|
|
|
|
!beforeText.isEmpty()) {
|
|
|
|
m_output.write(beforeText);
|
|
|
|
}
|
|
|
|
|
2022-02-24 09:28:52 +00:00
|
|
|
// The replacement string can be empty if we're only pointing something out to the user
|
|
|
|
QStringView replacementString = fixItem.replacementString.isEmpty()
|
|
|
|
? issueLocationWithContext.issueText()
|
|
|
|
: fixItem.replacementString;
|
|
|
|
|
|
|
|
// But if there's nothing to change it has to be a hint
|
|
|
|
if (fixItem.replacementString.isEmpty())
|
|
|
|
Q_ASSERT(fixItem.isHint);
|
|
|
|
|
|
|
|
m_output.write(replacementString, QtDebugMsg);
|
2021-08-13 07:44:42 +00:00
|
|
|
m_output.write(issueLocationWithContext.afterText().toString() + u'\n');
|
2021-07-01 11:55:11 +00:00
|
|
|
|
|
|
|
int tabCount = issueLocationWithContext.beforeText().count(u'\t');
|
2022-02-25 11:15:06 +00:00
|
|
|
|
|
|
|
// Do not draw location indicator for multiline replacement strings
|
2022-02-24 09:28:52 +00:00
|
|
|
if (replacementString.contains(u'\n'))
|
2022-02-25 11:15:06 +00:00
|
|
|
continue;
|
|
|
|
|
2022-03-21 09:21:18 +00:00
|
|
|
m_output.write(u" "_s.repeated(
|
2021-07-01 11:55:11 +00:00
|
|
|
issueLocationWithContext.beforeText().length() - tabCount)
|
2022-03-21 09:21:18 +00:00
|
|
|
+ u"\t"_s.repeated(tabCount)
|
|
|
|
+ u"^"_s.repeated(fixItem.replacementString.length()) + u'\n');
|
2021-07-01 11:55:11 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-22 12:41:14 +00:00
|
|
|
|
|
|
|
QT_END_NAMESPACE
|