4#include <QtCore/qcompilerdetection.h>
11#include <QtCore/qlist.h>
14#include <private/qqmljslogger_p.h>
15#include <private/qqmlsa_p.h>
17#include <QtQmlCompiler/qqmljsloggingutils.h>
19#include <QtCore/qglobal.h>
20#include <QtCore/qfile.h>
21#include <QtCore/qfileinfo.h>
81 static const QList<QQmlJS::LoggerCategory> cats = {
92 QStringLiteral(
"Warn about failing imports and deprecated qmltypes"),
99 QStringLiteral(
"Warn about with statements as they can cause false "
100 "positives when checking for unqualified access"),
144 "Warn about making deferred properties immediate by giving them an id."),
148 QStringLiteral(
"Warn about unqualified identifiers and how to fix them"),
166 "aren't reused. This is handled by the QtQuick "
167 "lint plugin. Use Quick.AttachedPropertyReuse instead."),
198 return m_location ==
other.m_location && m_fixDescription ==
other.m_fixDescription
199 && m_replacement ==
other.m_replacement && m_filename ==
other.m_filename
200 && m_hint ==
other.m_hint && m_autoApplicable ==
other.m_autoApplicable;
205 return !(*
this ==
other);
210 return m_categories.
values();
216 qWarning() <<
"Trying to re-register existing logger category" <<
category.name();
237 bool showFileName,
const std::optional<QQmlJSFixSuggestion> &suggestion,
238 const QString overrideFileName)
247 if (srcLocation.isValid()
248 && m_ignoredWarnings[srcLocation.startLine].contains(
id.name().toString()))
253 if ((!overrideFileName.isEmpty() || !m_fileName.
isEmpty()) && showFileName)
255 (!overrideFileName.isEmpty() ? overrideFileName : m_fileName) +
QStringLiteral(
":");
257 if (srcLocation.isValid())
258 prefix +=
QStringLiteral(
"%1:%2:").arg(srcLocation.startLine).arg(srcLocation.startColumn);
273 diagMsg.id =
id.name();
274 diagMsg.loc = srcLocation;
276 diagMsg.fixSuggestion = suggestion;
285 if (srcLocation.length > 0 && !m_code.
isEmpty() && showContext)
286 printContext(overrideFileName, srcLocation);
288 if (suggestion.has_value())
289 printFix(suggestion.value());
308void QQmlJSLogger::printContext(
const QString &overrideFileName,
321 if (
const QStringView beforeText = issueLocationWithContext.beforeText(); !beforeText.isEmpty())
322 m_output.
write(beforeText);
324 bool locationMultiline = issueLocationWithContext.issueText().contains(
QLatin1Char(
'\n'));
326 if (!issueLocationWithContext.issueText().isEmpty())
328 m_output.
write(issueLocationWithContext.afterText().toString() +
QLatin1Char(
'\n'));
331 if (locationMultiline)
334 int tabCount = issueLocationWithContext.beforeText().count(
QLatin1Char(
'\t'));
349 if (!fixItem.location().isValid())
352 const QString filename = fixItem.filename();
353 if (filename == currentFile) {
355 }
else if (filename.
isEmpty() || filename == currentFileAbsPath) {
362 currentFile = filename;
367 if (
const QStringView beforeText = issueLocationWithContext.beforeText();
368 !beforeText.isEmpty()) {
369 m_output.
write(beforeText);
373 const QString replacement = fixItem.replacement();
375 ? issueLocationWithContext.issueText()
382 m_output.
write(issueLocationWithContext.afterText().toString() + u
'\n');
384 int tabCount = issueLocationWithContext.beforeText().count(u
'\t');
387 if (replacementString.contains(u
'\n'))
390 m_output.
write(u
" "_s.repeated(
391 issueLocationWithContext.beforeText().size() - tabCount)
392 + u
"\t"_s.repeated(tabCount)
393 + u
"^"_s.repeated(replacement.
size()) + u
'\n');
399 : 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)
QString absolutePath() const
Returns the absolute path of the file system entry this QFileInfo refers to, excluding the entry's na...
QFILE_MAYBE_NODISCARD 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.
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
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)
QAnyStringView name() const
\macro QT_RESTRICTED_CAST_FROM_ASCII
static QString fromLatin1(QByteArrayView ba)
This is an overloaded member function, provided for convenience. It differs from the above function o...
bool isEmpty() const noexcept
Returns true if the string has no characters; otherwise returns false.
qsizetype size() const noexcept
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...
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 QQmlSA::LoggerWarningId qmlPrefixedImportType
const QQmlSA::LoggerWarningId qmlAliasCycle
const QQmlSA::LoggerWarningId qmlRestrictedType
const QQmlSA::LoggerWarningId qmlSignalParameters
const QQmlSA::LoggerWarningId qmlPlugin
const QQmlSA::LoggerWarningId qmlUnresolvedAlias
const QQmlSA::LoggerWarningId qmlDuplicatePropertyBinding
const QQmlSA::LoggerWarningId qmlRecursionDepthErrors
const QQmlSA::LoggerWarningId qmlSyntaxIdQuotation
const QQmlSA::LoggerWarningId qmlDuplicatedName
const QQmlSA::LoggerWarningId qmlReadOnlyProperty
const QQmlSA::LoggerWarningId qmlUncreatableType
const QQmlSA::LoggerWarningId qmlUseProperFunction
const QQmlSA::LoggerWarningId qmlMissingProperty
const QQmlSA::LoggerWarningId qmlMultilineStrings
const QQmlSA::LoggerWarningId qmlSyntaxDuplicateIds
const QQmlSA::LoggerWarningId qmlUnqualified
const QQmlSA::LoggerWarningId qmlMissingEnumEntry
const QQmlSA::LoggerWarningId qmlRequired
const QQmlSA::LoggerWarningId qmlTopLevelComponent
const QQmlSA::LoggerWarningId qmlDeferredPropertyId
const QQmlSA::LoggerWarningId qmlVarUsedBeforeDeclaration
const QQmlSA::LoggerWarningId qmlAccessSingleton
const QQmlSA::LoggerWarningId qmlWith
static bool isMsgTypeLess(QtMsgType a, QtMsgType b)
const QQmlSA::LoggerWarningId qmlInvalidLintDirective
const QQmlSA::LoggerWarningId qmlUnresolvedType
const QQmlSA::LoggerWarningId qmlImport
const QQmlSA::LoggerWarningId qmlMissingType
const QQmlSA::LoggerWarningId qmlInheritanceCycle
const QQmlSA::LoggerWarningId qmlIncompatibleType
const QQmlSA::LoggerWarningId qmlUnusedImports
const QQmlSA::LoggerWarningId qmlDeprecated
const QQmlSA::LoggerWarningId qmlAttachedPropertyReuse
const QQmlSA::LoggerWarningId qmlCompiler
const QQmlSA::LoggerWarningId qmlSyntax
const QQmlSA::LoggerWarningId qmlNonListProperty
static QString absolutePath(const QString &path)
#define QStringLiteral(str)
\inmodule QtCore \reentrant