diff options
author | Maximilian Goldstein <max.goldstein@qt.io> | 2022-03-16 13:19:54 +0100 |
---|---|---|
committer | Maximilian Goldstein <max.goldstein@qt.io> | 2022-04-05 14:06:56 +0200 |
commit | 7c9276d38b311042235a476e7421b64549b43413 (patch) | |
tree | 7d11a591f183fc00f229e84778b19790a0c95ef3 /tools/qmllint/main.cpp | |
parent | 93193747e8065c5c6c3c33c67c4383b7148b818c (diff) |
qmllint: Integrate plugin infrastructure
Integrates the plugin and pass infrastructure into qmlcompiler and qmllint proper.
Plugins are searched for in the "qmllint" subfolder of the Qt installation's plugin
directory. In addition we also support loading statically linked plugins.
[ChangeLog][qmllint][New Feature] qmllint can now be extended via plugins. Use --plugins
to get a list of available plugins.
Original-patch-by: Fabian Kosmale <fabian.kosmale@qt.io>
Change-Id: I75a09dd978fc7724aca4931f055cc71c7ced971b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint/main.cpp')
-rw-r--r-- | tools/qmllint/main.cpp | 56 |
1 files changed, 49 insertions, 7 deletions
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp index 2a09dd51a5..8fd4d9d2a1 100644 --- a/tools/qmllint/main.cpp +++ b/tools/qmllint/main.cpp @@ -158,9 +158,25 @@ All warnings can be set to three levels: "suggestions without applying them")); parser.addOption(dryRun); + QCommandLineOption listPluginsOption(QStringList() << "list-plugins", + QLatin1String("List all available plugins")); + parser.addOption(listPluginsOption); + + QCommandLineOption pluginsDisable(QStringList() << "disable-plugins", + QLatin1String("Disable all qmllint plugins")); + parser.addOption(pluginsDisable); + const QString pluginsDisableSettings = QLatin1String("DisablePlugins"); + settings.addOption(pluginsDisableSettings, false); + + QCommandLineOption pluginPathsOption( + QStringList() << "P" + << "plugin-paths", + QLatin1String("Look for qmllint plugins in specified directory"), + QLatin1String("directory")); + parser.addOption(pluginPathsOption); + parser.addPositionalArgument(QLatin1String("files"), QLatin1String("list of qml or js files to verify")); - parser.process(app); if (parser.isSet(writeDefaultsOption)) { @@ -192,11 +208,6 @@ All warnings can be set to three levels: updateLogLevels(); - const auto positionalArguments = parser.positionalArguments(); - if (positionalArguments.isEmpty()) { - parser.showHelp(-1); - } - bool silent = parser.isSet(silentOption); bool useAbsolutePath = parser.isSet(absolutePath); bool useJson = parser.isSet(jsonOption); @@ -233,7 +244,32 @@ All warnings can be set to three levels: QStringList resourceFiles = defaultResourceFiles; bool success = true; - QQmlJSLinter linter(qmlImportPaths, useAbsolutePath); + + QStringList pluginPaths = { QQmlJSLinter::defaultPluginPath() }; + + if (parser.isSet(pluginPathsOption)) + pluginPaths << parser.values(pluginPathsOption); + + QQmlJSLinter linter(qmlImportPaths, pluginPaths, useAbsolutePath); + + if (parser.isSet(listPluginsOption)) { + const std::vector<QQmlJSLinter::Plugin> &plugins = linter.plugins(); + if (!plugins.empty()) { + qInfo().nospace().noquote() << "Plugin\t\t\tVersion\tAuthor\t\tDescription"; + for (const QQmlJSLinter::Plugin &plugin : plugins) { + qInfo().nospace().noquote() << plugin.name() << "\t\t\t" << plugin.version() << "\t" + << plugin.author() << "\t\t" << plugin.description(); + } + } else { + qInfo() << "No plugins installed."; + } + return 0; + } + + const auto positionalArguments = parser.positionalArguments(); + if (positionalArguments.isEmpty()) { + parser.showHelp(-1); + } QJsonArray jsonFiles; @@ -272,6 +308,12 @@ All warnings can be set to three levels: qmlImportPaths << parser.values(qmlImportPathsOption); addAbsolutePaths(qmlImportPaths, settings.value(qmlImportPathsSetting).toStringList()); + + const bool disablePlugins = parser.isSet(pluginsDisable) + || (settings.isSet(pluginsDisableSettings) + && settings.value(pluginsDisableSettings).toBool()); + + linter.setPluginsEnabled(!disablePlugins); } const bool isFixing = parser.isSet(fixFile); |