aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSami Shalayel <sami.shalayel@qt.io>2024-10-01 18:02:10 +0200
committerSami Shalayel <sami.shalayel@qt.io>2024-11-13 16:08:08 +0000
commit8e176007865ceb6126ecc091354181574b347ecc (patch)
tree3c28a780c41c95f68a5d9b26209ef1c1ecf9367c
parentab60395394b30c1b441c50efc1d49017fe1faee8 (diff)
qmllint: load plugins from the correct paths
Make qmllint load plugins from the same default directories as QFactoryLoader does, in addition to the extra paths passed by command line arguments to qmllint. Remove the static helper method to get the custom qmllint default plugin directories and use QCoreApplication::libraryPaths() instead. This allows to ship the qmllint plugins with qmlls's standalone build, because QCoreApplication::libraryPaths() contains the current application path and allows a standalone qmlls to load plugins for linting or completion from a subfolder. Fix tst_sanity to continue ignoring the warnings from all other plugin as QQmlJSLinter will load all available default plugins now, like the Quick plugin for example. Change-Id: I9edaddb0fd5da27f68da9ceca76a9351fc0c6aee Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
-rw-r--r--src/qmlcompiler/qqmljslinter.cpp21
-rw-r--r--src/qmlcompiler/qqmljslinter_p.h4
-rw-r--r--tests/auto/quickcontrols/sanity/tst_sanity.cpp21
-rw-r--r--tools/qmllint/main.cpp2
4 files changed, 29 insertions, 19 deletions
diff --git a/src/qmlcompiler/qqmljslinter.cpp b/src/qmlcompiler/qqmljslinter.cpp
index a8826acbd3..f2cdfea20e 100644
--- a/src/qmlcompiler/qqmljslinter.cpp
+++ b/src/qmlcompiler/qqmljslinter.cpp
@@ -60,18 +60,13 @@ private:
QQmlJSLogger *m_logger;
};
-QString QQmlJSLinter::defaultPluginPath()
-{
- return QLibraryInfo::path(QLibraryInfo::PluginsPath) + QDir::separator() + u"qmllint";
-}
-
-QQmlJSLinter::QQmlJSLinter(const QStringList &importPaths, const QStringList &pluginPaths,
+QQmlJSLinter::QQmlJSLinter(const QStringList &importPaths, const QStringList &extraPluginPaths,
bool useAbsolutePath)
: m_useAbsolutePath(useAbsolutePath),
m_enablePlugins(true),
m_importer(importPaths, nullptr, UseOptionalImports)
{
- m_plugins = loadPlugins(pluginPaths);
+ m_plugins = loadPlugins(extraPluginPaths);
}
QQmlJSLinter::Plugin::Plugin(QQmlJSLinter::Plugin &&plugin) noexcept
@@ -208,7 +203,7 @@ bool QQmlJSLinter::Plugin::parseMetaData(const QJsonObject &metaData, QString pl
return true;
}
-std::vector<QQmlJSLinter::Plugin> QQmlJSLinter::loadPlugins(QStringList paths)
+std::vector<QQmlJSLinter::Plugin> QQmlJSLinter::loadPlugins(QStringList extraPluginPaths)
{
std::vector<Plugin> plugins;
@@ -230,6 +225,14 @@ std::vector<QQmlJSLinter::Plugin> QQmlJSLinter::loadPlugins(QStringList paths)
}
#if QT_CONFIG(library)
+ const QStringList paths = [&extraPluginPaths]() {
+ QStringList result{ extraPluginPaths };
+ const QStringList libraryPaths = QCoreApplication::libraryPaths();
+ for (const auto &path : libraryPaths) {
+ result.append(path + u"/qmllint"_s);
+ }
+ return result;
+ }();
for (const QString &pluginDir : paths) {
QDirIterator it{ pluginDir, QDir::Files };
@@ -255,7 +258,7 @@ std::vector<QQmlJSLinter::Plugin> QQmlJSLinter::loadPlugins(QStringList paths)
}
}
#endif
- Q_UNUSED(paths)
+ Q_UNUSED(extraPluginPaths)
return plugins;
}
diff --git a/src/qmlcompiler/qqmljslinter_p.h b/src/qmlcompiler/qqmljslinter_p.h
index 5f367df4c6..3f6584cef5 100644
--- a/src/qmlcompiler/qqmljslinter_p.h
+++ b/src/qmlcompiler/qqmljslinter_p.h
@@ -41,8 +41,7 @@ class LintPlugin;
class Q_QMLCOMPILER_EXPORT QQmlJSLinter
{
public:
- QQmlJSLinter(const QStringList &importPaths,
- const QStringList &pluginPaths = { QQmlJSLinter::defaultPluginPath() },
+ QQmlJSLinter(const QStringList &importPaths, const QStringList &extraPluginPaths = {},
bool useAbsolutePath = false);
enum LintResult { FailedToOpen, FailedToParse, HasWarnings, LintSuccess };
@@ -106,7 +105,6 @@ public:
};
static std::vector<Plugin> loadPlugins(QStringList paths);
- static QString defaultPluginPath();
LintResult lintFile(const QString &filename, const QString *fileContents, const bool silent,
QJsonArray *json, const QStringList &qmlImportPaths,
diff --git a/tests/auto/quickcontrols/sanity/tst_sanity.cpp b/tests/auto/quickcontrols/sanity/tst_sanity.cpp
index 01524e4a89..f939449254 100644
--- a/tests/auto/quickcontrols/sanity/tst_sanity.cpp
+++ b/tests/auto/quickcontrols/sanity/tst_sanity.cpp
@@ -66,12 +66,21 @@ tst_Sanity::tst_Sanity()
m_linter.setPluginsEnabled(true);
for (auto &category : m_categories) {
- if (category.id() == qmlDeferredPropertyId || category.id() == qmlAttachedPropertyReuse) {
- category.setLevel(QtWarningMsg);
- category.setIgnored(false);
- } else {
- category.setLevel(QtCriticalMsg);
- category.setIgnored(true);
+ category.setLevel(QtCriticalMsg);
+ category.setIgnored(true);
+ }
+
+ for (auto &plugin: m_linter.plugins()) {
+ if (plugin.name() != u"QuickControlsSanity") {
+ plugin.setEnabled(false);
+ continue;
+ }
+
+ for (const auto &category: plugin.categories()) {
+ m_categories.append(category);
+ m_categories.back().setLevel(QtWarningMsg);
+ m_categories.back().setIgnored(false);
+
}
}
}
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index 3ceb83e397..9bf5147b1d 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -284,7 +284,7 @@ All warnings can be set to three levels:
bool success = true;
- QStringList pluginPaths = { QQmlJSLinter::defaultPluginPath() };
+ QStringList pluginPaths;
if (parser.isSet(pluginPathsOption))
pluginPaths << parser.values(pluginPathsOption);