diff options
author | Sami Shalayel <[email protected]> | 2024-10-22 14:54:08 +0200 |
---|---|---|
committer | Sami Shalayel <[email protected]> | 2024-10-29 13:00:19 +0100 |
commit | 282add1abf18171ea6d24777b928b900e672111d (patch) | |
tree | 16664f8c7e1b266685091c737a990ce1bc88b011 /src | |
parent | 49eacf98d5e8857282735dc4356f20de8302908c (diff) |
qmllint: allow plugins to set default category level
Add a defaultLevel value to the .json file shipped with the plugins that
allow plugins to set the default level of their categories.
Change-Id: I4a13366ce705ba104414b41e729d12769ab83821
Reviewed-by: Olivier De Cannière <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/qmlcompiler/qqmljslinter.cpp | 10 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsloggingutils.cpp | 31 | ||||
-rw-r--r-- | src/qmlcompiler/qqmljsloggingutils_p.h | 1 |
3 files changed, 32 insertions, 10 deletions
diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp index a9983d6887..1ffe6e5fc4 100644 --- a/src/qmlcompiler/qqmljslinter.cpp +++ b/src/qmlcompiler/qqmljslinter.cpp @@ -192,6 +192,16 @@ bool QQmlJSLinter::Plugin::parseMetaData(const QJsonObject &metaData, QString pl m_categories << QQmlJS::LoggerCategory{ categoryId, settingsName, object["description"_L1].toString(), QtWarningMsg, ignored }; + const auto itLevel = object.find("defaultLevel"_L1); + if (itLevel == object.end()) + continue; + + const QString level = itLevel->toString(); + if (!QQmlJS::LoggingUtils::applyLevelToCategory(level, m_categories.last())) { + qWarning() << "Invalid logging level" << level << "provided for" + << m_categories.last().id().name().toString() + << "(allowed are: disable, info, warning) found in plugin metadata"; + } } return true; diff --git a/src/qmlcompiler/qqmljsloggingutils.cpp b/src/qmlcompiler/qqmljsloggingutils.cpp index 3b628d4438..168a003c36 100644 --- a/src/qmlcompiler/qqmljsloggingutils.cpp +++ b/src/qmlcompiler/qqmljsloggingutils.cpp @@ -154,6 +154,26 @@ QString levelToString(const QQmlJS::LoggerCategory &category) } }; +bool applyLevelToCategory(const QStringView level, LoggerCategory &category) +{ + if (level == "disable"_L1) { + category.setLevel(QtCriticalMsg); + category.setIgnored(true); + return true; + } + if (level == "info"_L1) { + category.setLevel(QtInfoMsg); + category.setIgnored(false); + return true; + } + if (level == "warning"_L1) { + category.setLevel(QtWarningMsg); + category.setIgnored(false); + return true; + } + return false; +}; + /*! \internal Sets the category levels from a settings file and an optional parser. @@ -185,16 +205,7 @@ void updateLogLevels(QList<LoggerCategory> &categories, if (value.isEmpty()) continue; - if (value == "disable"_L1) { - category.setLevel(QtCriticalMsg); - category.setIgnored(true); - } else if (value == "info"_L1) { - category.setLevel(QtInfoMsg); - category.setIgnored(false); - } else if (value == "warning"_L1) { - category.setLevel(QtWarningMsg); - category.setIgnored(false); - } else { + if (!applyLevelToCategory(value, category)) { qWarning() << "Invalid logging level" << value << "provided for" << category.id().name().toString() << "(allowed are: disable, info, warning)"; diff --git a/src/qmlcompiler/qqmljsloggingutils_p.h b/src/qmlcompiler/qqmljsloggingutils_p.h index e3d2dcb1f2..8623e1878f 100644 --- a/src/qmlcompiler/qqmljsloggingutils_p.h +++ b/src/qmlcompiler/qqmljsloggingutils_p.h @@ -110,6 +110,7 @@ Q_QMLCOMPILER_EXPORT void updateLogLevels(QList<LoggerCategory> &categories, QCommandLineParser *parser); Q_QMLCOMPILER_EXPORT QString levelToString(const QQmlJS::LoggerCategory &category); +Q_QMLCOMPILER_EXPORT bool applyLevelToCategory(const QStringView level, LoggerCategory &category); } // namespace LoggingUtils } // namespace QQmlJS |