Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljslinterrenamedcomponents.cpp
Go to the documentation of this file.
1// Copyright (C) 2026 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
6
8
9namespace QQmlJS {
10
11using namespace Qt::StringLiterals;
12
13static QString qmlNameFromFilePath(QStringView path)
14{
15 if (!path.endsWith(".qml"_L1))
16 return {};
17
18 QStringView result(path);
19 result.chop(".qml"_L1.size());
20 if (result.endsWith(".ui"_L1))
21 result.chop(".ui"_L1.size());
22 const qsizetype start = path.lastIndexOf("/"_L1);
23 result.slice(start == -1 ? 0 : start + 1);
24 return result.toString();
25}
26
27static void removeModuleImportQualifiers(QStringList *names)
28{
29 for (QString &name : *names) {
30 if (qsizetype idx = name.lastIndexOf(u'.'); idx != -1)
31 name.slice(idx + 1);
32 }
33}
34
35void LinterRenamedComponents::handleRenamedType(const QQmlJSScope::ConstPtr &scope,
36 const QStringView name,
37 const QQmlJS::SourceLocation &location,
38 QQmlJSLogger *logger) const
39{
40 if (scope.isNull())
41 return;
42
43 const auto factory = scope.factory();
44 const QString oldName = qmlNameFromFilePath(factory ? factory->filePath() : scope->filePath());
45 if (oldName != name)
46 return;
47
48 QStringList names = m_scopeToName->values(scope);
49 removeModuleImportQualifiers(&names);
50 auto begin = names.begin();
51 auto end = std::remove(begin, names.end(), oldName);
52 std::sort(begin, end);
53 names.erase(std::unique(begin, end), names.end());
54
55 if (names.size() == 0)
56 return;
57
58 logger->log(
59 "\"%2\" is explicitly renamed to \"%1\" via a qmldir entry or QT_QML_SOURCE_TYPENAME CMake property, use \"%1\" instead."_L1
60 .arg(qJoin(names.begin(), names.end(), QString(), "\", \""_L1), name),
61 qmlRenamedType, location);
62}
63} // namespace QQmlJS
64
65QT_END_NAMESPACE
void handleRenamedType(const QQmlJSScope::ConstPtr &scope, const QStringView name, const QQmlJS::SourceLocation &location, QQmlJSLogger *logger) const
static void removeModuleImportQualifiers(QStringList *names)
static QString qmlNameFromFilePath(QStringView path)
Combined button and popup list for selecting options.