diff options
author | Sami Shalayel <[email protected]> | 2024-10-21 15:22:50 +0200 |
---|---|---|
committer | Sami Shalayel <[email protected]> | 2024-11-04 22:15:02 +0100 |
commit | c4455f1771483c8ed63d27454242f19b28b524b0 (patch) | |
tree | 285c3136702dfed449c0ebbdd4b65af7b54c39d6 /src/qmlcompiler/qqmljsloggingutils.cpp | |
parent | 9d797294fa49b0ccc1ebf22bce1897cd863e8dd3 (diff) |
qmllint plugins: prefix settingsname with plugin name
Prefix the logging category name with the plugin's name, in the same way
as the category id's are also prefixed.
Fixed a test from bc709184afcb8373be6d69309cb53294455d7248 that did not
test anything. Add a flag to callQmllint() that enables to read settings,
and make sure that a warning is actually emitted when the settings are
not read for the settings/plugin/elementPass_pluginTest.qml file.
The latter file was also renamed because the test lint plugin only
enables itself on files ending with "pluginTest.qml".
Add a compatibility mode that allows loading "old" .qmllint.ini files
where the settings names do not contain the plugin name.
[ChangeLog][Important Behavior Change] Qmllint prefixes logging
categories from plugins with the plugin name in .qmllint.ini files.
For example, PropertyChangesParsed=disable becomes
Quick.PropertyChangesParsed=disable.
Fixes: QTBUG-130357
Change-Id: I47a0bf22991d6a438aa3371c666da34f2c2835bc
Reviewed-by: Fabian Kosmale <[email protected]>
Diffstat (limited to 'src/qmlcompiler/qqmljsloggingutils.cpp')
-rw-r--r-- | src/qmlcompiler/qqmljsloggingutils.cpp | 47 |
1 files changed, 33 insertions, 14 deletions
diff --git a/src/qmlcompiler/qqmljsloggingutils.cpp b/src/qmlcompiler/qqmljsloggingutils.cpp index 168a003c36..03327f65c4 100644 --- a/src/qmlcompiler/qqmljsloggingutils.cpp +++ b/src/qmlcompiler/qqmljsloggingutils.cpp @@ -154,6 +154,38 @@ QString levelToString(const QQmlJS::LoggerCategory &category) } }; +static QStringList settingsNamesForCategory(const LoggerCategory &category) +{ + const QString name = category.settingsName(); + const QStringList result{ QStringLiteral("Warnings/") += name, + QStringLiteral("Warnings/") += name.sliced(name.indexOf(u'.') + 1) }; + return result; +} + +static QString levelValueForCategory(const LoggerCategory &category, + const QQmlToolingSettings &settings, + QCommandLineParser *parser) +{ + const QString key = category.id().name().toString(); + if (parser && parser->isSet(key)) + return parser->value(key); + + const QStringList settingsName = settingsNamesForCategory(category); + for (const QString &settingsName : settingsName) { + if (!settings.isSet(settingsName)) + continue; + const QString value = settings.value(settingsName).toString(); + + // Do not try to set the levels if it's due to a default config option. + // This way we can tell which options have actually been overwritten by the user. + if (levelToString(category) == value) + return QString(); + + return value; + } + return QString(); +} + bool applyLevelToCategory(const QStringView level, LoggerCategory &category) { if (level == "disable"_L1) { @@ -188,20 +220,7 @@ void updateLogLevels(QList<LoggerCategory> &categories, if (category.isDefault()) continue; - const QString value = [&] () { - const QString key = category.id().name().toString(); - if (parser && parser->isSet(key)) - return parser->value(key); - - // Do not try to set the levels if it's due to a default config option. - // This way we can tell which options have actually been overwritten by the user. - const QString settingsName = QStringLiteral("Warnings/") + category.settingsName(); - const QString value = settings.value(settingsName).toString(); - if (levelToString(category) == value) - return QString(); - - return value; - }(); + const QString value = levelValueForCategory(category, settings, parser); if (value.isEmpty()) continue; |