4#include <private/qqmljslogger_p.h>
5#include <private/qqmlsa_p.h>
7#include <QtQmlCompiler/qqmljsloggingutils.h>
9#include <QtCore/qglobal.h>
10#include <QtCore/qfile.h>
11#include <QtCore/qfileinfo.h>
19#include <QtCore/qlist.h>
90 QStringLiteral(
"Warn about failing imports and deprecated qmltypes"),
97 QStringLiteral(
"Warn about with statements as they can cause false "
98 "positives when checking for unqualified access"),
142 "Warn about making deferred properties immediate by giving them an id."),
146 QStringLiteral(
"Warn about unqualified identifiers and how to fix them"),
164 "aren't reused. This is handled by the QtQuick "
165 "lint plugin. Use Quick.AttachedPropertyReuse instead."),
196 return m_location ==
other.m_location && m_fixDescription ==
other.m_fixDescription
197 && m_replacement ==
other.m_replacement && m_filename ==
other.m_filename
198 && m_hint ==
other.m_hint && m_autoApplicable ==
other.m_autoApplicable;
203 return !(*
this ==
other);
208 return m_categories.
values();
214 qWarning() <<
"Trying to re-register existing logger category" <<
category.name();
235 bool showFileName,
const std::optional<QQmlJSFixSuggestion> &suggestion,
236 const QString overrideFileName)
246 && m_ignoredWarnings[srcLocation.
startLine].contains(
id.name().toString()))
251 if ((!overrideFileName.
isEmpty() || !m_fileName.
isEmpty()) && showFileName)
271 diagMsg.
id =
id.name();
272 diagMsg.
loc = srcLocation;
283 if (srcLocation.
length > 0 && !m_code.
isEmpty() && showContext)
284 printContext(overrideFileName, srcLocation);
286 if (suggestion.has_value())
287 printFix(suggestion.value());
306void QQmlJSLogger::printContext(
const QString &overrideFileName,
319 if (
const QStringView beforeText = issueLocationWithContext.beforeText(); !beforeText.isEmpty())
320 m_output.
write(beforeText);
322 bool locationMultiline = issueLocationWithContext.issueText().contains(
QLatin1Char(
'\n'));
324 if (!issueLocationWithContext.issueText().isEmpty())
326 m_output.
write(issueLocationWithContext.afterText().toString() +
QLatin1Char(
'\n'));
329 if (locationMultiline)
332 int tabCount = issueLocationWithContext.beforeText().count(
QLatin1Char(
'\t'));
351 if (filename == currentFile) {
353 }
else if (filename.
isEmpty() || filename == currentFileAbsPath) {
360 currentFile = filename;
365 if (
const QStringView beforeText = issueLocationWithContext.beforeText();
366 !beforeText.isEmpty()) {
367 m_output.
write(beforeText);
373 ? issueLocationWithContext.issueText()
380 m_output.
write(issueLocationWithContext.afterText().toString() + u
'\n');
382 int tabCount = issueLocationWithContext.beforeText().count(u
'\t');
385 if (replacementString.
contains(u
'\n'))
388 m_output.
write(u
" "_s.repeated(
389 issueLocationWithContext.beforeText().size() - tabCount)
390 + u
"\t"_s.repeated(tabCount)
391 + u
"^"_s.repeated(replacement.
size()) + u
'\n');
397 : m_location{
location }, m_fixDescription{ fixDescription }, m_replacement{ replacement }
QString toString() const
Returns a deep copy of this string view's data as a QString.
void write(const QStringView message, int color=-1)
void writePrefixedMessage(const QString &message, QtMsgType type, const QString &prefix=QString())
void insertMapping(int colorID, ColorCode colorCode)
\inmodule QtCore \reentrant
QString absolutePath() const
Returns a file's path absolute path.
bool open(OpenMode flags) override
Opens the file using OpenMode mode, returning true if successful; otherwise false.
bool contains(const Key &key) const noexcept
Returns true if the hash contains an item with the key; otherwise returns false.
QByteArray readAll()
Reads all remaining data from the device, and returns it as a byte array.
bool isEmpty() const noexcept
void push_back(parameter_type t)
iterator insert(const Key &key, const T &value)
bool contains(const Key &key) const
QList< T > values() const
bool operator!=(const QQmlJSFixSuggestion &) const
bool operator==(const QQmlJSFixSuggestion &) const
QQmlJSFixSuggestion()=default
QQmlJS::SourceLocation location() const
bool isAutoApplicable() const
QString replacement() const
QString fixDescription() const
void processMessages(const QList< QQmlJS::DiagnosticMessage > &messages, const QQmlJS::LoggerWarningId id)
bool isCategoryIgnored(QQmlJS::LoggerWarningId id) const
QList< QQmlJS::LoggerCategory > categories() const
static const QList< QQmlJS::LoggerCategory > & defaultCategories()
void log(const QString &message, QQmlJS::LoggerWarningId id, const QQmlJS::SourceLocation &srcLocation, bool showContext=true, bool showFileName=true, const std::optional< QQmlJSFixSuggestion > &suggestion={}, const QString overrideFileName=QString())
void registerCategory(const QQmlJS::LoggerCategory &category)
const QAnyStringView name() const
bool contains(QChar c, Qt::CaseSensitivity cs=Qt::CaseSensitive) const noexcept
\macro QT_RESTRICTED_CAST_FROM_ASCII
QString repeated(qsizetype times) const
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
qsizetype size() const
Returns the number of characters in this string.
static QString fromUtf8(QByteArrayView utf8)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const
Returns true if the string has no characters; otherwise returns false.
QString & append(QChar c)
const QLoggingCategory & category()
[1]
Combined button and popup list for selecting options.
#define QT_WARNING_DISABLE_GCC(text)
GLboolean GLboolean GLboolean b
GLenum GLuint GLint level
GLboolean GLboolean GLboolean GLboolean a
[7]
GLuint GLsizei const GLchar * message
const QQmlJS::LoggerWarningId qmlUnqualified
const QQmlJS::LoggerWarningId qmlNonListProperty
const QQmlJS::LoggerWarningId qmlUseProperFunction
const QQmlJS::LoggerWarningId qmlPlugin
const QQmlJS::LoggerWarningId qmlImport
const QQmlJS::LoggerWarningId qmlSignalParameters
const QQmlJS::LoggerWarningId qmlDuplicatedName
const QQmlJS::LoggerWarningId qmlTopLevelComponent
const QQmlJS::LoggerWarningId qmlRestrictedType
const QQmlJS::LoggerWarningId qmlUnusedImports
const QQmlJS::LoggerWarningId qmlPrefixedImportType
const QQmlJS::LoggerWarningId qmlSyntaxDuplicateIds
const QQmlJS::LoggerWarningId qmlWith
const QQmlJS::LoggerWarningId qmlCompiler
const QQmlJS::LoggerWarningId qmlMissingEnumEntry
const QQmlJS::LoggerWarningId qmlUnresolvedType
const QQmlJS::LoggerWarningId qmlRequired
const QQmlJS::LoggerWarningId qmlDuplicatePropertyBinding
const QQmlJS::LoggerWarningId qmlReadOnlyProperty
const QQmlJS::LoggerWarningId qmlMissingProperty
const QQmlJS::LoggerWarningId qmlUncreatableType
const QQmlJS::LoggerWarningId qmlRecursionDepthErrors
static bool isMsgTypeLess(QtMsgType a, QtMsgType b)
const QQmlJS::LoggerWarningId qmlDeprecated
const QQmlJS::LoggerWarningId qmlAttachedPropertyReuse
const QQmlJS::LoggerWarningId qmlVarUsedBeforeDeclaration
const QQmlJS::LoggerWarningId qmlInvalidLintDirective
const QQmlJS::LoggerWarningId qmlSyntaxIdQuotation
const QQmlJS::LoggerWarningId qmlMissingType
const QQmlJS::LoggerWarningId qmlDeferredPropertyId
const QQmlJS::LoggerWarningId qmlAliasCycle
const QQmlJS::LoggerWarningId qmlUnresolvedAlias
const QQmlJS::LoggerWarningId qmlMultilineStrings
const QQmlJS::LoggerWarningId qmlSyntax
const QQmlJS::LoggerWarningId qmlAccessSingleton
const QQmlJS::LoggerWarningId qmlInheritanceCycle
const QQmlJS::LoggerWarningId qmlIncompatibleType
static QString absolutePath(const QString &path)
#define QStringLiteral(str)
std::optional< QQmlJSFixSuggestion > fixSuggestion
\inmodule QtCore \reentrant