aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2025-08-22 09:13:47 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2025-12-22 17:52:41 +0100
commit73991630dea9558d66a8f304984b72e177ef1f98 (patch)
treea601064c3e200b6a7a958c997b91ab20862d150b /src
parent04466da863f51a852cbb19814c05016018d7ca54 (diff)
Compiler: Reuse location serialization lamba
The logic was performed in two different ways just a few lines apart. Change-Id: I2a4c964009edaee7c37421cb6ef4f95ea1935f7e Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io> Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qmlcompiler/qqmljslinter.cpp17
1 files changed, 7 insertions, 10 deletions
diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp
index b3c66dca2e..9e2d04dca0 100644
--- a/src/qmlcompiler/qqmljslinter.cpp
+++ b/src/qmlcompiler/qqmljslinter.cpp
@@ -456,22 +456,19 @@ static void addJsonWarning(QJsonArray &warnings, const QQmlJS::DiagnosticMessage
jsonMessage[u"type"_s] = type;
jsonMessage[u"id"_s] = id.toString();
- if (message.loc.isValid()) {
- jsonMessage[u"line"_s] = static_cast<int>(message.loc.startLine);
- jsonMessage[u"column"_s] = static_cast<int>(message.loc.startColumn);
- jsonMessage[u"charOffset"_s] = static_cast<int>(message.loc.offset);
- jsonMessage[u"length"_s] = static_cast<int>(message.loc.length);
- }
-
- jsonMessage[u"message"_s] = message.message;
-
- QJsonArray suggestions;
const auto convertLocation = [](const QQmlJS::SourceLocation &source, QJsonObject *target) {
target->insert("line"_L1, int(source.startLine));
target->insert("column"_L1, int(source.startColumn));
target->insert("charOffset"_L1, int(source.offset));
target->insert("length"_L1, int(source.length));
};
+
+ if (message.loc.isValid())
+ convertLocation(message.loc, &jsonMessage);
+
+ jsonMessage[u"message"_s] = message.message;
+
+ QJsonArray suggestions;
if (suggestion.has_value()) {
QJsonObject jsonFix {
{ "message"_L1, suggestion->fixDescription() },