aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmllint/main.cpp
diff options
context:
space:
mode:
authorOlivier De Cannière <olivier.decanniere@qt.io>2023-05-05 09:30:27 +0200
committerOlivier De Cannière <olivier.decanniere@qt.io>2023-05-30 13:42:35 +0200
commitcdd7fe05f676ed1664a156beaf63093237a3beac (patch)
tree8f7adccde1adc0e8404a96a895c5170b84f3f0cc /tools/qmllint/main.cpp
parent65cb77165ba18442a524faf44f712ae26661965c (diff)
QQmlSA: Create an abstraction layer for static analysis
This patch adds abstractions for QML Elements, Bindings, Methods and Properties. This abstraction layer avoids exposing internal details and should be more suited for static analysis tasks. It is now possible to write qmllint plugins without including private headers. As a drive-by, change tst_qmllint:verifyJsRoot to open files in text mode instead of binary. This fixes an issue where line endings cause issues on Windows. Fixes: QTBUG-102276 Change-Id: I6b6e53f1e0078734a18f3aa51807fbe875b375f0 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r--tools/qmllint/main.cpp54
1 files changed, 40 insertions, 14 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 947a13da08..b244868a17 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -6,6 +6,7 @@
#include <QtQmlCompiler/private/qqmljsresourcefilemapper_p.h>
#include <QtQmlCompiler/private/qqmljscompiler_p.h>
#include <QtQmlCompiler/private/qqmljslinter_p.h>
+#include <QtQmlCompiler/private/qqmljsloggingutils_p.h>
#include <QtCore/qdebug.h>
#include <QtCore/qfile.h>
@@ -32,7 +33,7 @@ constexpr int JSON_LOGGING_FORMAT_REVISION = 3;
int main(int argv, char *argc[])
{
QHashSeed::setDeterministicGlobalSeed();
- QList<QQmlJSLogger::Category> categories;
+ QList<QQmlJS::LoggerCategory> categories;
QCoreApplication app(argv, argc);
QCoreApplication::setApplicationName("qmllint");
@@ -150,20 +151,36 @@ All warnings can be set to three levels:
QLatin1String("directory"));
parser.addOption(pluginPathsOption);
- auto addCategory = [&](const QQmlJSLogger::Category &category) {
+ auto levelToString = [](const QQmlJS::LoggerCategory &category) -> QString {
+ Q_ASSERT(category.isIgnored() || category.level() != QtCriticalMsg);
+ if (category.isIgnored())
+ return QStringLiteral("disable");
+
+ switch (category.level()) {
+ case QtInfoMsg:
+ return QStringLiteral("info");
+ case QtWarningMsg:
+ return QStringLiteral("warning");
+ default:
+ Q_UNREACHABLE();
+ break;
+ }
+ };
+
+ auto addCategory = [&](const QQmlJS::LoggerCategory &category) {
categories.push_back(category);
- if (category.isDefault)
+ if (category.isDefault())
return;
QCommandLineOption option(
category.id().name().toString(),
- category.description
- + QStringLiteral(" (default: %1)").arg(category.levelToString()),
- QStringLiteral("level"), category.levelToString());
- if (category.ignored)
+ category.description()
+ + QStringLiteral(" (default: %1)").arg(levelToString(category)),
+ QStringLiteral("level"), levelToString(category));
+ if (category.isIgnored())
option.setFlags(QCommandLineOption::HiddenFromHelp);
parser.addOption(option);
- settings.addOption(QStringLiteral("Warnings/") + category.settingsName,
- category.levelToString());
+ settings.addOption(QStringLiteral("Warnings/") + category.settingsName(),
+ levelToString(category));
};
for (const auto &category : QQmlJSLogger::defaultCategories()) {
@@ -192,21 +209,30 @@ All warnings can be set to three levels:
auto updateLogLevels = [&]() {
for (auto &category : categories) {
- if (category.isDefault)
+ if (category.isDefault())
continue;
const QString &key = category.id().name().toString();
- const QString &settingsName = QStringLiteral("Warnings/") + category.settingsName;
+ const QString &settingsName = QStringLiteral("Warnings/") + category.settingsName();
if (parser.isSet(key) || settings.isSet(settingsName)) {
const QString value = parser.isSet(key) ? parser.value(key)
: 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 (category.levelToString() == value && !parser.isSet(key))
+ if (levelToString(category) == value && !parser.isSet(key))
continue;
- if (!category.setLevel(value)) {
+ 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 {
qWarning() << "Invalid logging level" << value << "provided for"
<< category.id().name().toString()
<< "(allowed are: disable, info, warning)";
@@ -267,7 +293,7 @@ All warnings can be set to three levels:
QQmlJSLinter linter(qmlImportPaths, pluginPaths, useAbsolutePath);
for (const QQmlJSLinter::Plugin &plugin : linter.plugins()) {
- for (const QQmlJSLogger::Category &category : plugin.categories())
+ for (const QQmlJS::LoggerCategory &category : plugin.categories())
addCategory(category);
}