From 58895fe56550dbdd6bcced92f1f7f9dffd83c93a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Olivier=20De=20Canni=C3=A8re?= Date: Fri, 15 Aug 2025 14:27:35 +0200 Subject: [PATCH] qmllint: Update JSON format to include hints into fix suggestions Hints are no longer their own fix suggestion but instead are part of an existing one. This breaks compatibility with the existing format but as the output is not documented and is versioned this should be ok. This change will enable having multiple fix suggestions per warning in a future change. Change-Id: Iedf275507554a2d70399757396e278999874cd53 Reviewed-by: Ulf Hermann (cherry picked from commit 243883ed78cb1132a65ce064285d1305449d2ebf) Reviewed-by: Qt Cherry-pick Bot --- src/qmlcompiler/qqmljslinter.cpp | 17 ++--------------- tools/qmllint/main.cpp | 2 +- 2 files changed, 3 insertions(+), 16 deletions(-) diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp index 4fa0e03ccf..cf4ca9e149 100644 --- a/src/qmlcompiler/qqmljslinter.cpp +++ b/src/qmlcompiler/qqmljslinter.cpp @@ -471,31 +471,18 @@ static void addJsonWarning(QJsonArray &warnings, const QQmlJS::DiagnosticMessage QJsonObject jsonFix { { "message"_L1, suggestion->fixDescription() }, { "replacement"_L1, suggestion->replacement() }, - { "isHint"_L1, !suggestion->isAutoApplicable() }, + { "isAutoApplicable"_L1, suggestion->isAutoApplicable() }, + { "hint"_L1, suggestion->hint() }, }; convertLocation(suggestion->location(), &jsonFix); const QString filename = suggestion->filename(); if (!filename.isEmpty()) jsonFix.insert("fileName"_L1, filename); suggestions << jsonFix; - - const QString hint = suggestion->hint(); - if (!hint.isEmpty()) { - // We need to keep compatibility with the JSON format. - // Therefore the overly verbose encoding of the hint. - QJsonObject jsonHint { - { "message"_L1, hint }, - { "replacement"_L1, QString() }, - { "isHint"_L1, true } - }; - convertLocation(QQmlJS::SourceLocation(), &jsonHint); - suggestions << jsonHint; - } } jsonMessage[u"suggestions"] = suggestions; warnings << jsonMessage; - } void QQmlJSLinter::processMessages(QJsonArray &warnings) diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index a865d96bba..d570d17057 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -30,7 +30,7 @@ using namespace Qt::StringLiterals; -constexpr int JSON_LOGGING_FORMAT_REVISION = 3; +constexpr int JSON_LOGGING_FORMAT_REVISION = 4; bool argumentsFromCommandLineAndFile(QStringList& allArguments, const QStringList &arguments) {