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
|
|
|
|
2023-08-10 21:36:57 +00:00
|
|
|
#include <QtCore/qcompilerdetection.h>
|
|
|
|
// GCC 11 thinks diagMsg.fixSuggestion.fixes.d.ptr is somehow uninitialized in
|
|
|
|
// QList::emplaceBack(), probably called from QQmlJsLogger::log()
|
|
|
|
// Ditto for GCC 12, but it emits a different warning
|
|
|
|
QT_WARNING_PUSH
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wuninitialized")
|
|
|
|
QT_WARNING_DISABLE_GCC("-Wmaybe-uninitialized")
|
|
|
|
#include <QtCore/qlist.h>
|
|
|
|
QT_WARNING_POP
|
|
|
|
|
2023-06-05 08:47:43 +00:00
|
|
|
#include <private/qqmljslogger_p.h>
|
|
|
|
#include <private/qqmlsa_p.h>
|
|
|
|
|
|
|
|
#include <QtQmlCompiler/qqmljsloggingutils.h>
|
|
|
|
|
|
|
|
#include <QtCore/qglobal.h>
|
|
|
|
#include <QtCore/qfile.h>
|
|
|
|
#include <QtCore/qfileinfo.h>
|
2022-01-12 17:10:41 +00:00
|
|
|
|
|
|
|
|
2021-11-22 12:41:14 +00:00
|
|
|
QT_BEGIN_NAMESPACE
|
|
|
|
|
2022-03-21 09:21:18 +00:00
|
|
|
using namespace Qt::StringLiterals;
|
|
|
|
|
2023-09-18 13:40:45 +00:00
|
|
|
const QQmlSA::LoggerWarningId qmlRequired{ "required" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlAliasCycle{ "alias-cycle" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUnresolvedAlias{ "unresolved-alias" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlImport{ "import" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlRecursionDepthErrors{ "recursion-depth-errors" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlWith{ "with" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlInheritanceCycle{ "inheritance-cycle" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlDeprecated{ "deprecated" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlSignalParameters{ "signal-handler-parameters" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlMissingType{ "missing-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUnresolvedType{ "unresolved-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlRestrictedType{ "restricted-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlPrefixedImportType{ "prefixed-import-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlIncompatibleType{ "incompatible-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlMissingProperty{ "missing-property" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlNonListProperty{ "non-list-property" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlReadOnlyProperty{ "read-only-property" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlDuplicatePropertyBinding{ "duplicate-property-binding" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlDuplicatedName{ "duplicated-name" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlDeferredPropertyId{ "deferred-property-id" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUnqualified{ "unqualified" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUnusedImports{ "unused-imports" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlMultilineStrings{ "multiline-strings" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlSyntax{ "syntax" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlSyntaxIdQuotation{ "syntax.id-quotation" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlSyntaxDuplicateIds{ "syntax.duplicate-ids" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlCompiler{ "compiler" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlAttachedPropertyReuse{ "attached-property-reuse" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlPlugin{ "plugin" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlVarUsedBeforeDeclaration{ "var-used-before-declaration" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlInvalidLintDirective{ "invalid-lint-directive" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUseProperFunction{ "use-proper-function" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlAccessSingleton{ "access-singleton-via-object" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlTopLevelComponent{ "top-level-component" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlUncreatableType{ "uncreatable-type" };
|
|
|
|
const QQmlSA::LoggerWarningId qmlMissingEnumEntry{ "missing-enum-entry" };
|
2023-05-05 07:30:27 +00:00
|
|
|
|
|
|
|
QQmlJSLogger::QQmlJSLogger()
|
2022-05-30 12:52:03 +00:00
|
|
|
{
|
2023-05-05 07:30:27 +00:00
|
|
|
static const QList<QQmlJS::LoggerCategory> cats = defaultCategories();
|
|
|
|
|
|
|
|
for (const QQmlJS::LoggerCategory &category : cats)
|
|
|
|
registerCategory(category);
|
|
|
|
|
|
|
|
// setup color output
|
|
|
|
m_output.insertMapping(QtCriticalMsg, QColorOutput::RedForeground);
|
|
|
|
m_output.insertMapping(QtWarningMsg, QColorOutput::PurpleForeground); // Yellow?
|
|
|
|
m_output.insertMapping(QtInfoMsg, QColorOutput::BlueForeground);
|
|
|
|
m_output.insertMapping(QtDebugMsg, QColorOutput::GreenForeground); // None?
|
|
|
|
}
|
|
|
|
|
|
|
|
const QList<QQmlJS::LoggerCategory> &QQmlJSLogger::defaultCategories()
|
|
|
|
{
|
|
|
|
static const QList<QQmlJS::LoggerCategory> cats = {
|
|
|
|
QQmlJS::LoggerCategory{ qmlRequired.name().toString(), QStringLiteral("RequiredProperty"),
|
|
|
|
QStringLiteral("Warn about required properties"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlAliasCycle.name().toString(),
|
|
|
|
QStringLiteral("PropertyAliasCycles"),
|
|
|
|
QStringLiteral("Warn about alias cycles"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlUnresolvedAlias.name().toString(),
|
|
|
|
QStringLiteral("PropertyAliasCycles"),
|
|
|
|
QStringLiteral("Warn about unresolved aliases"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
2022-05-30 12:52:03 +00:00
|
|
|
qmlImport.name().toString(), QStringLiteral("ImportFailure"),
|
|
|
|
QStringLiteral("Warn about failing imports and deprecated qmltypes"),
|
|
|
|
QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{
|
2022-05-30 12:52:03 +00:00
|
|
|
qmlRecursionDepthErrors.name().toString(), QStringLiteral("ImportFailure"),
|
|
|
|
QStringLiteral("Warn about failing imports and deprecated qmltypes"), QtWarningMsg,
|
|
|
|
false, true },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{ qmlWith.name().toString(), QStringLiteral("WithStatement"),
|
|
|
|
QStringLiteral("Warn about with statements as they can cause false "
|
|
|
|
"positives when checking for unqualified access"),
|
|
|
|
QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlInheritanceCycle.name().toString(),
|
|
|
|
QStringLiteral("InheritanceCycle"),
|
|
|
|
QStringLiteral("Warn about inheritance cycles"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlDeprecated.name().toString(), QStringLiteral("Deprecated"),
|
|
|
|
QStringLiteral("Warn about deprecated properties and types"),
|
|
|
|
QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
2022-07-06 08:15:30 +00:00
|
|
|
qmlSignalParameters.name().toString(), QStringLiteral("BadSignalHandlerParameters"),
|
|
|
|
QStringLiteral("Warn about bad signal handler parameters"), QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{ qmlMissingType.name().toString(), QStringLiteral("MissingType"),
|
|
|
|
QStringLiteral("Warn about missing types"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlUnresolvedType.name().toString(),
|
|
|
|
QStringLiteral("UnresolvedType"),
|
|
|
|
QStringLiteral("Warn about unresolved types"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlRestrictedType.name().toString(),
|
|
|
|
QStringLiteral("RestrictedType"),
|
|
|
|
QStringLiteral("Warn about restricted types"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlPrefixedImportType.name().toString(),
|
|
|
|
QStringLiteral("PrefixedImportType"),
|
|
|
|
QStringLiteral("Warn about prefixed import types"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlIncompatibleType.name().toString(),
|
|
|
|
QStringLiteral("IncompatibleType"),
|
|
|
|
QStringLiteral("Warn about missing types"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlMissingProperty.name().toString(),
|
|
|
|
QStringLiteral("MissingProperty"),
|
|
|
|
QStringLiteral("Warn about missing properties"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlNonListProperty.name().toString(),
|
|
|
|
QStringLiteral("NonListProperty"),
|
|
|
|
QStringLiteral("Warn about non-list properties"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
2022-07-06 08:15:30 +00:00
|
|
|
qmlReadOnlyProperty.name().toString(), QStringLiteral("ReadOnlyProperty"),
|
|
|
|
QStringLiteral("Warn about writing to read-only properties"), QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{ qmlDuplicatePropertyBinding.name().toString(),
|
|
|
|
QStringLiteral("DuplicatePropertyBinding"),
|
|
|
|
QStringLiteral("Warn about duplicate property bindings"),
|
|
|
|
QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
|
|
|
qmlDuplicatedName.name().toString(), QStringLiteral("DuplicatedName"),
|
|
|
|
QStringLiteral("Warn about duplicated property/signal names"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
2022-05-30 12:52:03 +00:00
|
|
|
qmlDeferredPropertyId.name().toString(), QStringLiteral("DeferredPropertyId"),
|
|
|
|
QStringLiteral(
|
|
|
|
"Warn about making deferred properties immediate by giving them an id."),
|
2022-08-30 14:33:48 +00:00
|
|
|
QtInfoMsg, true, true },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{
|
2022-05-30 12:52:03 +00:00
|
|
|
qmlUnqualified.name().toString(), QStringLiteral("UnqualifiedAccess"),
|
|
|
|
QStringLiteral("Warn about unqualified identifiers and how to fix them"),
|
|
|
|
QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{ qmlUnusedImports.name().toString(), QStringLiteral("UnusedImports"),
|
|
|
|
QStringLiteral("Warn about unused imports"), QtInfoMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlMultilineStrings.name().toString(),
|
|
|
|
QStringLiteral("MultilineStrings"),
|
|
|
|
QStringLiteral("Warn about multiline strings"), QtInfoMsg },
|
|
|
|
QQmlJS::LoggerCategory{ qmlSyntax.name().toString(), QString(),
|
|
|
|
QStringLiteral("Syntax errors"), QtWarningMsg, false, true },
|
|
|
|
QQmlJS::LoggerCategory{ qmlSyntaxIdQuotation.name().toString(), QString(),
|
|
|
|
QStringLiteral("ID quotation"), QtWarningMsg, false, true },
|
|
|
|
QQmlJS::LoggerCategory{ qmlSyntaxDuplicateIds.name().toString(), QString(),
|
|
|
|
QStringLiteral("ID duplication"), QtCriticalMsg, false, true },
|
|
|
|
QQmlJS::LoggerCategory{ qmlCompiler.name().toString(), QStringLiteral("CompilerWarnings"),
|
|
|
|
QStringLiteral("Warn about compiler issues"), QtWarningMsg, true },
|
|
|
|
QQmlJS::LoggerCategory{
|
|
|
|
qmlAttachedPropertyReuse.name().toString(), QStringLiteral("AttachedPropertyReuse"),
|
|
|
|
QStringLiteral("Warn if attached types from parent components "
|
|
|
|
"aren't reused. This is handled by the QtQuick "
|
|
|
|
"lint plugin. Use Quick.AttachedPropertyReuse instead."),
|
|
|
|
QtCriticalMsg, true },
|
|
|
|
QQmlJS::LoggerCategory{ qmlPlugin.name().toString(), QStringLiteral("LintPluginWarnings"),
|
|
|
|
QStringLiteral("Warn if a qmllint plugin finds an issue"),
|
|
|
|
QtWarningMsg, true },
|
|
|
|
QQmlJS::LoggerCategory{ qmlVarUsedBeforeDeclaration.name().toString(),
|
|
|
|
QStringLiteral("VarUsedBeforeDeclaration"),
|
|
|
|
QStringLiteral("Warn if a variable is used before declaration"),
|
|
|
|
QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
2022-07-06 08:15:30 +00:00
|
|
|
qmlInvalidLintDirective.name().toString(), QStringLiteral("InvalidLintDirective"),
|
|
|
|
QStringLiteral("Warn if an invalid qmllint comment is found"), QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{
|
2022-07-06 08:15:30 +00:00
|
|
|
qmlUseProperFunction.name().toString(), QStringLiteral("UseProperFunction"),
|
|
|
|
QStringLiteral("Warn if var is used for storing functions"), QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{
|
2022-07-06 08:15:30 +00:00
|
|
|
qmlAccessSingleton.name().toString(), QStringLiteral("AccessSingletonViaObject"),
|
2022-09-12 14:40:56 +00:00
|
|
|
QStringLiteral("Warn if a singleton is accessed via an object"), QtWarningMsg },
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerCategory{
|
|
|
|
qmlTopLevelComponent.name().toString(), QStringLiteral("TopLevelComponent"),
|
|
|
|
QStringLiteral("Fail when a top level Component are encountered"), QtWarningMsg },
|
|
|
|
QQmlJS::LoggerCategory{
|
|
|
|
qmlUncreatableType.name().toString(), QStringLiteral("UncreatableType"),
|
|
|
|
QStringLiteral("Warn if uncreatable types are created"), QtWarningMsg }
|
2021-04-19 14:54:45 +00:00
|
|
|
};
|
2021-03-30 10:58:26 +00:00
|
|
|
|
2022-05-30 12:52:03 +00:00
|
|
|
return cats;
|
2021-03-30 10:58:26 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
bool QQmlJSFixSuggestion::operator==(const QQmlJSFixSuggestion &other) const
|
2022-05-30 12:52:03 +00:00
|
|
|
{
|
2023-05-05 07:30:27 +00:00
|
|
|
return m_location == other.m_location && m_fixDescription == other.m_fixDescription
|
|
|
|
&& m_replacement == other.m_replacement && m_filename == other.m_filename
|
|
|
|
&& m_hint == other.m_hint && m_autoApplicable == other.m_autoApplicable;
|
2022-05-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
bool QQmlJSFixSuggestion::operator!=(const QQmlJSFixSuggestion &other) const
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
2023-05-05 07:30:27 +00:00
|
|
|
return !(*this == other);
|
2022-05-30 12:52:03 +00:00
|
|
|
}
|
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
QList<QQmlJS::LoggerCategory> QQmlJSLogger::categories() const
|
2022-05-30 12:52:03 +00:00
|
|
|
{
|
2023-05-05 07:30:27 +00:00
|
|
|
return m_categories.values();
|
|
|
|
}
|
2022-05-30 12:52:03 +00:00
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
void QQmlJSLogger::registerCategory(const QQmlJS::LoggerCategory &category)
|
|
|
|
{
|
|
|
|
if (m_categories.contains(category.name())) {
|
|
|
|
qWarning() << "Trying to re-register existing logger category" << category.name();
|
|
|
|
return;
|
|
|
|
}
|
2021-03-25 14:34:42 +00:00
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
m_categoryLevels[category.name()] = category.level();
|
|
|
|
m_categoryIgnored[category.name()] = category.isIgnored();
|
|
|
|
m_categories.insert(category.name(), category);
|
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];
|
|
|
|
}
|
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
void QQmlJSLogger::log(const QString &message, QQmlJS::LoggerWarningId id,
|
2021-07-01 15:30:42 +00:00
|
|
|
const QQmlJS::SourceLocation &srcLocation, QtMsgType type, bool showContext,
|
2023-02-06 11:14:38 +00:00
|
|
|
bool showFileName, const std::optional<QQmlJSFixSuggestion> &suggestion,
|
2022-02-24 09:28:52 +00:00
|
|
|
const QString overrideFileName)
|
2021-07-01 15:30:42 +00:00
|
|
|
{
|
2022-05-30 12:52:03 +00:00
|
|
|
Q_ASSERT(m_categoryLevels.contains(id.name().toString()));
|
|
|
|
|
|
|
|
if (isCategoryIgnored(id))
|
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
|
|
|
|
|
2022-05-30 12:52:03 +00:00
|
|
|
if (srcLocation.isValid()
|
|
|
|
&& m_ignoredWarnings[srcLocation.startLine].contains(id.name().toString()))
|
2021-05-27 12:32:43 +00:00
|
|
|
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())
|
2024-09-04 06:40:08 +00:00
|
|
|
prefix += QStringLiteral("%1:%2: ").arg(srcLocation.startLine).arg(srcLocation.startColumn);
|
|
|
|
else if (!prefix.isEmpty())
|
|
|
|
prefix += QStringLiteral(": "); // produce double colon for Qt Creator's issues pane
|
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
|
|
|
// 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
|
2022-06-30 10:48:12 +00:00
|
|
|
m_output.writePrefixedMessage(u"%1%2 [%3]"_s.arg(prefix, message, id.name().toString()), 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;
|
2022-06-30 10:48:12 +00:00
|
|
|
diagMsg.id = id.name();
|
2021-03-25 14:34:42 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2022-11-25 12:25:40 +00:00
|
|
|
if (srcLocation.length > 0 && !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,
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJS::LoggerWarningId id)
|
2021-03-25 14:34:42 +00:00
|
|
|
{
|
2022-05-30 12:52:03 +00:00
|
|
|
if (messages.isEmpty() || isCategoryIgnored(id))
|
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)
|
2022-05-30 12:52:03 +00:00
|
|
|
log(message.message, id, 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;
|
2022-10-05 05:29:16 +00:00
|
|
|
m_output.write(QString::fromLatin1(" ").repeated(issueLocationWithContext.beforeText().size()
|
2021-07-05 10:48:49 +00:00
|
|
|
- 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
|
|
|
|
2023-02-06 11:14:38 +00:00
|
|
|
void QQmlJSLogger::printFix(const QQmlJSFixSuggestion &fixItem)
|
2021-07-01 11:55:11 +00:00
|
|
|
{
|
2022-02-24 09:28:52 +00:00
|
|
|
const QString currentFileAbsPath = QFileInfo(m_fileName).absolutePath();
|
|
|
|
QString code = m_code;
|
|
|
|
QString currentFile;
|
2023-02-06 11:14:38 +00:00
|
|
|
m_output.writePrefixedMessage(fixItem.fixDescription(), QtInfoMsg);
|
|
|
|
|
|
|
|
if (!fixItem.location().isValid())
|
|
|
|
return;
|
|
|
|
|
|
|
|
const QString filename = fixItem.filename();
|
|
|
|
if (filename == currentFile) {
|
|
|
|
// Nothing to do in this case, we've already read the code
|
|
|
|
} else if (filename.isEmpty() || filename == currentFileAbsPath) {
|
|
|
|
code = m_code;
|
|
|
|
} else {
|
|
|
|
QFile file(filename);
|
|
|
|
const bool success = file.open(QFile::ReadOnly);
|
|
|
|
Q_ASSERT(success);
|
|
|
|
code = QString::fromUtf8(file.readAll());
|
|
|
|
currentFile = filename;
|
2021-07-01 11:55:11 +00:00
|
|
|
}
|
2023-02-06 11:14:38 +00:00
|
|
|
|
|
|
|
IssueLocationWithContext issueLocationWithContext { code, fixItem.location() };
|
|
|
|
|
|
|
|
if (const QStringView beforeText = issueLocationWithContext.beforeText();
|
|
|
|
!beforeText.isEmpty()) {
|
|
|
|
m_output.write(beforeText);
|
|
|
|
}
|
|
|
|
|
|
|
|
// The replacement string can be empty if we're only pointing something out to the user
|
|
|
|
const QString replacement = fixItem.replacement();
|
|
|
|
QStringView replacementString = replacement.isEmpty()
|
|
|
|
? issueLocationWithContext.issueText()
|
|
|
|
: replacement;
|
|
|
|
|
|
|
|
// But if there's nothing to change it cannot be auto-applied
|
|
|
|
Q_ASSERT(!replacement.isEmpty() || !fixItem.isAutoApplicable());
|
|
|
|
|
|
|
|
m_output.write(replacementString, QtDebugMsg);
|
|
|
|
m_output.write(issueLocationWithContext.afterText().toString() + u'\n');
|
|
|
|
|
|
|
|
int tabCount = issueLocationWithContext.beforeText().count(u'\t');
|
|
|
|
|
|
|
|
// Do not draw location indicator for multiline replacement strings
|
|
|
|
if (replacementString.contains(u'\n'))
|
|
|
|
return;
|
|
|
|
|
|
|
|
m_output.write(u" "_s.repeated(
|
|
|
|
issueLocationWithContext.beforeText().size() - tabCount)
|
|
|
|
+ u"\t"_s.repeated(tabCount)
|
|
|
|
+ u"^"_s.repeated(replacement.size()) + u'\n');
|
2021-07-01 11:55:11 +00:00
|
|
|
}
|
2021-11-22 12:41:14 +00:00
|
|
|
|
2023-05-05 07:30:27 +00:00
|
|
|
QQmlJSFixSuggestion::QQmlJSFixSuggestion(const QString &fixDescription,
|
|
|
|
const QQmlJS::SourceLocation &location,
|
|
|
|
const QString &replacement)
|
|
|
|
: m_location{ location }, m_fixDescription{ fixDescription }, m_replacement{ replacement }
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2021-11-22 12:41:14 +00:00
|
|
|
QT_END_NAMESPACE
|