diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2021-05-27 14:32:43 +0200 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2021-06-03 08:54:57 +0200 |
commit | 9f389ee75dfcbf8ad56fa4ceac0f28d2a81194e1 (patch) | |
tree | 3218652b643cc54a989960c15a59f16ba19f578c /src | |
parent | 609a21eac694f15c74c9f53b49473cd08588ef40 (diff) |
qmllint: Add ability to ignore individual warnings
Allows users to ignore individual warnings by adding a "// qmllint disable" comment in the line that triggers the warning.
This feature is especially useful for use in pre-commit / CI tests as it allows to add exceptions for individual warnings that cannot be fixed immediately.
[ChangeLog][qmllint][New Feature] You can now ignore individual warnings by adding "// qmllint disable"
in the line causing it. You may also specify one or more warning type to ignore ("// qmllint disable warningtype1 warningtype2...") which is preferable. This can also be done for entire blocks of code by using "// qmllint disable" in an empty line and ending it with "// qmllint enable"
Change-Id: Iea6c29132d6b51ecfb5e5d8a19a43446a7286c24
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljslogger.cpp | 3 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljslogger_p.h | 7 |
2 files changed, 10 insertions, 0 deletions
diff --git a/src/qmlcompiler/qqmljslogger.cpp b/src/qmlcompiler/qqmljslogger.cpp index 73d3ab0038..7f04e3b66e 100644 --- a/src/qmlcompiler/qqmljslogger.cpp +++ b/src/qmlcompiler/qqmljslogger.cpp @@ -103,6 +103,9 @@ void QQmlJSLogger::log(const QString &message, QQmlJSLoggerCategory category, co if (isCategoryDisabled(category)) return; + if (srcLocation.isValid() && m_ignoredWarnings[srcLocation.startLine].contains(category)) + return; + const QtMsgType msgType = m_categoryLevels[category]; QString prefix; diff --git a/src/qmlcompiler/qqmljslogger_p.h b/src/qmlcompiler/qqmljslogger_p.h index 5ac9df769c..5ccbe91045 100644 --- a/src/qmlcompiler/qqmljslogger_p.h +++ b/src/qmlcompiler/qqmljslogger_p.h @@ -48,6 +48,7 @@ #include <QtCore/qmap.h> #include <QtCore/qstring.h> #include <QtCore/qlist.h> +#include <QtCore/qset.h> /*! \internal @@ -181,6 +182,11 @@ public: void processMessages(const QList<QQmlJS::DiagnosticMessage> &messages, QQmlJSLoggerCategory category); + void ignoreWarnings(uint32_t line, const QSet<QQmlJSLoggerCategory> &categories) + { + m_ignoredWarnings[line] = categories; + } + QColorOutput &colorOutput() { return m_output; } private: @@ -197,6 +203,7 @@ private: QList<QQmlJS::DiagnosticMessage> m_infos; QList<QQmlJS::DiagnosticMessage> m_warnings; QList<QQmlJS::DiagnosticMessage> m_errors; + QHash<uint32_t, QSet<QQmlJSLoggerCategory>> m_ignoredWarnings; }; #endif // QLOGGER_H |