2014-07-09 12:28:23 +00:00
|
|
|
/****************************************************************************
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** Copyright (C) 2016 Klaralvdalens Datakonsult AB, a KDAB Group company, info@kdab.com, author Sergio Martins <sergio.martins@kdab.com>
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2014-07-09 12:28:23 +00:00
|
|
|
**
|
|
|
|
** This file is part of the plugins of the Qt Toolkit.
|
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** $QT_BEGIN_LICENSE:GPL-EXCEPT$
|
2014-07-09 12:28:23 +00:00
|
|
|
** Commercial License Usage
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2015-01-28 11:55:39 +00:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
2016-01-19 11:23:05 +00:00
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2014-07-09 12:28:23 +00:00
|
|
|
**
|
2016-01-19 11:23:05 +00:00
|
|
|
** GNU General Public License Usage
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2014-07-09 12:28:23 +00:00
|
|
|
**
|
|
|
|
** $QT_END_LICENSE$
|
|
|
|
**
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
#include "findwarnings.h"
|
2021-07-05 10:48:49 +00:00
|
|
|
#include "codegen.h"
|
2021-08-02 14:50:27 +00:00
|
|
|
#include "codegenwarninginterface.h"
|
2021-05-12 16:32:57 +00:00
|
|
|
#include "../shared/qqmltoolingsettings.h"
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2021-02-22 15:12:57 +00:00
|
|
|
#include <QtQmlCompiler/private/qqmljsresourcefilemapper_p.h>
|
2021-07-05 10:48:49 +00:00
|
|
|
#include <QtQmlCompiler/private/qqmljscompiler_p.h>
|
2021-02-22 15:12:57 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
#include <QtQml/private/qqmljslexer_p.h>
|
|
|
|
#include <QtQml/private/qqmljsparser_p.h>
|
|
|
|
#include <QtQml/private/qqmljsengine_p.h>
|
|
|
|
#include <QtQml/private/qqmljsastvisitor_p.h>
|
|
|
|
#include <QtQml/private/qqmljsast_p.h>
|
|
|
|
|
|
|
|
#include <QtCore/qdebug.h>
|
|
|
|
#include <QtCore/qfile.h>
|
|
|
|
#include <QtCore/qfileinfo.h>
|
|
|
|
#include <QtCore/qcoreapplication.h>
|
2020-09-29 14:55:15 +00:00
|
|
|
#include <QtCore/qdiriterator.h>
|
2021-06-01 09:03:12 +00:00
|
|
|
#include <QtCore/qjsonobject.h>
|
|
|
|
#include <QtCore/qjsonarray.h>
|
|
|
|
#include <QtCore/qjsondocument.h>
|
|
|
|
#include <QtCore/qscopeguard.h>
|
2019-11-11 17:18:04 +00:00
|
|
|
|
2017-01-23 08:01:22 +00:00
|
|
|
#if QT_CONFIG(commandlineparser)
|
2019-11-11 17:18:04 +00:00
|
|
|
#include <QtCore/qcommandlineparser.h>
|
2017-01-23 08:01:22 +00:00
|
|
|
#endif
|
2014-07-09 12:28:23 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
#include <QtCore/qlibraryinfo.h>
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2021-06-01 09:03:12 +00:00
|
|
|
#include <cstdio>
|
|
|
|
|
|
|
|
constexpr int JSON_LOGGING_FORMAT_REVISION = 1;
|
|
|
|
|
|
|
|
static bool lint_file(const QString &filename, const bool silent, QJsonArray *json,
|
|
|
|
const QStringList &qmlImportPaths, const QStringList &qmltypesFiles,
|
2021-07-06 07:27:11 +00:00
|
|
|
const QStringList &resourceFiles,
|
2021-05-14 15:34:01 +00:00
|
|
|
const QMap<QString, QQmlJSLogger::Option> &options, QQmlJSImporter &importer)
|
2014-07-09 12:28:23 +00:00
|
|
|
{
|
2021-06-01 09:03:12 +00:00
|
|
|
QJsonArray warnings;
|
|
|
|
QJsonObject result;
|
|
|
|
|
|
|
|
bool success = true;
|
|
|
|
|
|
|
|
QScopeGuard jsonOutput([&] {
|
|
|
|
if (!json)
|
|
|
|
return;
|
|
|
|
|
|
|
|
result[u"filename"_qs] = QFileInfo(filename).absoluteFilePath();
|
|
|
|
result[u"warnings"] = warnings;
|
|
|
|
result[u"success"] = success;
|
|
|
|
|
|
|
|
json->append(result);
|
|
|
|
});
|
|
|
|
|
|
|
|
auto addJsonWarning = [&](const QQmlJS::DiagnosticMessage &message) {
|
|
|
|
QJsonObject jsonMessage;
|
|
|
|
|
|
|
|
QString type;
|
|
|
|
switch (message.type) {
|
|
|
|
case QtDebugMsg:
|
|
|
|
type = "debug";
|
|
|
|
break;
|
|
|
|
case QtWarningMsg:
|
|
|
|
type = "warning";
|
|
|
|
break;
|
|
|
|
case QtCriticalMsg:
|
|
|
|
type = "critical";
|
|
|
|
break;
|
|
|
|
case QtFatalMsg:
|
|
|
|
type = "fatal";
|
|
|
|
break;
|
|
|
|
case QtInfoMsg:
|
|
|
|
type = "info";
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
type = "unknown";
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonMessage[u"type"_qs] = type;
|
|
|
|
|
|
|
|
if (message.loc.isValid()) {
|
|
|
|
jsonMessage[u"line"_qs] = static_cast<int>(message.loc.startLine);
|
|
|
|
jsonMessage[u"column"_qs] = static_cast<int>(message.loc.startColumn);
|
|
|
|
jsonMessage[u"charOffset"_qs] = static_cast<int>(message.loc.offset);
|
|
|
|
jsonMessage[u"length"_qs] = static_cast<int>(message.loc.length);
|
|
|
|
}
|
|
|
|
|
|
|
|
jsonMessage[u"message"_qs] = message.message;
|
|
|
|
|
|
|
|
warnings << jsonMessage;
|
|
|
|
};
|
|
|
|
|
2014-07-09 12:28:23 +00:00
|
|
|
QFile file(filename);
|
|
|
|
if (!file.open(QFile::ReadOnly)) {
|
2021-06-01 09:03:12 +00:00
|
|
|
if (json) {
|
|
|
|
result[u"openFailed"] = true;
|
|
|
|
success = false;
|
|
|
|
} else if (!silent) {
|
2019-09-19 09:15:47 +00:00
|
|
|
qWarning() << "Failed to open file" << filename << file.error();
|
2021-06-01 09:03:12 +00:00
|
|
|
}
|
2014-07-09 12:28:23 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
QString code = QString::fromUtf8(file.readAll());
|
|
|
|
file.close();
|
|
|
|
|
|
|
|
QQmlJS::Engine engine;
|
|
|
|
QQmlJS::Lexer lexer(&engine);
|
|
|
|
|
|
|
|
QFileInfo info(filename);
|
2019-10-15 08:39:40 +00:00
|
|
|
const QString lowerSuffix = info.suffix().toLower();
|
|
|
|
const bool isESModule = lowerSuffix == QLatin1String("mjs");
|
2019-11-11 17:18:04 +00:00
|
|
|
const bool isJavaScript = isESModule || lowerSuffix == QLatin1String("js");
|
|
|
|
|
|
|
|
lexer.setCode(code, /*lineno = */ 1, /*qmlMode=*/ !isJavaScript);
|
2014-07-09 12:28:23 +00:00
|
|
|
QQmlJS::Parser parser(&engine);
|
|
|
|
|
2021-06-01 09:03:12 +00:00
|
|
|
success = isJavaScript ? (isESModule ? parser.parseModule() : parser.parseProgram())
|
|
|
|
: parser.parse();
|
2014-07-09 12:28:23 +00:00
|
|
|
|
|
|
|
if (!success && !silent) {
|
2016-08-11 10:37:27 +00:00
|
|
|
const auto diagnosticMessages = parser.diagnosticMessages();
|
|
|
|
for (const QQmlJS::DiagnosticMessage &m : diagnosticMessages) {
|
2021-06-01 09:03:12 +00:00
|
|
|
if (json) {
|
|
|
|
addJsonWarning(m);
|
|
|
|
} else {
|
|
|
|
qWarning().noquote() << QString::fromLatin1("%1:%2 : %3")
|
|
|
|
.arg(filename)
|
|
|
|
.arg(m.loc.startLine)
|
|
|
|
.arg(m.message);
|
|
|
|
}
|
2014-07-09 12:28:23 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-04-24 13:10:53 +00:00
|
|
|
if (success && !isJavaScript) {
|
2021-02-22 15:12:57 +00:00
|
|
|
const auto check = [&](QQmlJSResourceFileMapper *mapper) {
|
2021-05-14 15:34:01 +00:00
|
|
|
if (importer.importPaths() != qmlImportPaths)
|
|
|
|
importer.setImportPaths(qmlImportPaths);
|
|
|
|
|
|
|
|
importer.setResourceFileMapper(mapper);
|
|
|
|
|
2021-08-18 09:04:34 +00:00
|
|
|
QQmlJSLogger logger(filename, code, silent || json);
|
|
|
|
FindWarningVisitor v {
|
|
|
|
&importer,
|
|
|
|
&logger,
|
|
|
|
qmltypesFiles,
|
|
|
|
engine.comments(),
|
|
|
|
};
|
2021-03-25 14:34:42 +00:00
|
|
|
|
2021-03-30 10:58:26 +00:00
|
|
|
for (auto it = options.cbegin(); it != options.cend(); ++it) {
|
2021-08-18 09:04:34 +00:00
|
|
|
logger.setCategoryError(it.value().m_category, it.value().m_error);
|
|
|
|
logger.setCategoryLevel(it.value().m_category, it.value().m_level);
|
2021-03-30 10:58:26 +00:00
|
|
|
}
|
2021-03-25 14:34:42 +00:00
|
|
|
|
2021-02-22 15:12:57 +00:00
|
|
|
parser.rootNode()->accept(&v);
|
|
|
|
success = v.check();
|
2021-06-01 09:03:12 +00:00
|
|
|
|
2021-10-28 14:33:30 +00:00
|
|
|
if (logger.hasErrors())
|
|
|
|
return;
|
|
|
|
|
2021-09-30 09:39:23 +00:00
|
|
|
QQmlJSTypeInfo typeInfo;
|
|
|
|
Codegen codegen { &importer, filename, qmltypesFiles, &logger, &typeInfo, code };
|
2021-07-05 10:48:49 +00:00
|
|
|
QQmlJSSaveFunction saveFunction = [](const QV4::CompiledData::SaveableUnitPointer &,
|
|
|
|
const QQmlJSAotFunctionMap &,
|
|
|
|
QString *) { return true; };
|
|
|
|
|
|
|
|
QQmlJSCompileError error;
|
|
|
|
|
|
|
|
QLoggingCategory::setFilterRules(u"qt.qml.compiler=false"_qs);
|
|
|
|
|
2021-08-18 09:04:34 +00:00
|
|
|
CodegenWarningInterface interface(&logger);
|
2021-08-02 14:50:27 +00:00
|
|
|
qCompileQmlFile(filename, saveFunction, &codegen, &error, true, &interface);
|
2021-07-05 10:48:49 +00:00
|
|
|
|
2021-08-18 09:04:34 +00:00
|
|
|
success &= !logger.hasWarnings() && !logger.hasErrors();
|
2021-07-06 11:26:23 +00:00
|
|
|
|
2021-06-01 09:03:12 +00:00
|
|
|
if (json) {
|
2021-08-18 09:04:34 +00:00
|
|
|
for (const auto &error : logger.errors())
|
2021-06-01 09:03:12 +00:00
|
|
|
addJsonWarning(error);
|
2021-08-18 09:04:34 +00:00
|
|
|
for (const auto &warning : logger.warnings())
|
2021-06-01 09:03:12 +00:00
|
|
|
addJsonWarning(warning);
|
2021-08-18 09:04:34 +00:00
|
|
|
for (const auto &info : logger.infos())
|
2021-06-01 09:03:12 +00:00
|
|
|
addJsonWarning(info);
|
|
|
|
}
|
2021-02-22 15:12:57 +00:00
|
|
|
};
|
|
|
|
|
2021-07-06 07:27:11 +00:00
|
|
|
if (resourceFiles.isEmpty()) {
|
2021-02-22 15:12:57 +00:00
|
|
|
check(nullptr);
|
|
|
|
} else {
|
2021-07-06 07:27:11 +00:00
|
|
|
QQmlJSResourceFileMapper mapper(resourceFiles);
|
2021-02-22 15:12:57 +00:00
|
|
|
check(&mapper);
|
|
|
|
}
|
2019-06-14 12:21:25 +00:00
|
|
|
}
|
|
|
|
|
2014-07-09 12:28:23 +00:00
|
|
|
return success;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argv, char *argc[])
|
|
|
|
{
|
2021-05-14 15:34:01 +00:00
|
|
|
qSetGlobalQHashSeed(0);
|
2021-03-30 10:58:26 +00:00
|
|
|
QMap<QString, QQmlJSLogger::Option> options = QQmlJSLogger::options();
|
|
|
|
|
2014-07-09 12:28:23 +00:00
|
|
|
QCoreApplication app(argv, argc);
|
|
|
|
QCoreApplication::setApplicationName("qmllint");
|
2021-06-03 11:03:37 +00:00
|
|
|
QCoreApplication::setApplicationVersion(QT_VERSION_STR);
|
2017-01-23 08:01:22 +00:00
|
|
|
#if QT_CONFIG(commandlineparser)
|
2014-07-09 12:28:23 +00:00
|
|
|
QCommandLineParser parser;
|
2021-05-12 16:32:57 +00:00
|
|
|
QQmlToolingSettings settings(QLatin1String("qmllint"));
|
2021-03-30 10:58:26 +00:00
|
|
|
parser.setApplicationDescription(QLatin1String(R"(QML syntax verifier and analyzer
|
|
|
|
|
|
|
|
All warnings can be set to three levels:
|
|
|
|
disabled - Fully disables the warning.
|
|
|
|
info - Displays the warning but does not influence the return code.
|
|
|
|
warning - Displays the warning and leads to a non-zero exit code if encountered.
|
|
|
|
)"));
|
2021-08-25 12:14:38 +00:00
|
|
|
|
|
|
|
for (auto it = options.cbegin(); it != options.cend(); ++it) {
|
|
|
|
QCommandLineOption option(
|
|
|
|
it.key(),
|
|
|
|
it.value().m_description
|
|
|
|
+ QStringLiteral(" (default: %1)").arg(it.value().levelToString()),
|
|
|
|
QStringLiteral("level"), it.value().levelToString());
|
|
|
|
parser.addOption(option);
|
|
|
|
settings.addOption(QStringLiteral("Warnings/") + it.value().m_settingsName,
|
|
|
|
it.value().levelToString());
|
|
|
|
}
|
|
|
|
|
2014-07-09 12:28:23 +00:00
|
|
|
parser.addHelpOption();
|
|
|
|
parser.addVersionOption();
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
QCommandLineOption silentOption(QStringList() << "s" << "silent",
|
|
|
|
QLatin1String("Don't output syntax errors"));
|
2014-07-09 12:28:23 +00:00
|
|
|
parser.addOption(silentOption);
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2021-06-01 09:03:12 +00:00
|
|
|
QCommandLineOption jsonOption(QStringList() << "json",
|
|
|
|
QLatin1String("Output linting errors as JSON"));
|
|
|
|
parser.addOption(jsonOption);
|
|
|
|
|
2021-05-12 16:32:57 +00:00
|
|
|
QCommandLineOption writeDefaultsOption(
|
|
|
|
QStringList() << "write-defaults",
|
|
|
|
QLatin1String("Writes defaults settings to .qmllint.ini and exits (Warning: This "
|
|
|
|
"will overwrite any existing settings and comments!)"));
|
|
|
|
parser.addOption(writeDefaultsOption);
|
|
|
|
|
|
|
|
QCommandLineOption ignoreSettings(QStringList() << "ignore-settings",
|
|
|
|
QLatin1String("Ignores all settings files and only takes "
|
|
|
|
"command line options into consideration"));
|
|
|
|
parser.addOption(ignoreSettings);
|
|
|
|
|
2021-02-22 15:12:57 +00:00
|
|
|
QCommandLineOption resourceOption(
|
|
|
|
{ QStringLiteral("resource") },
|
|
|
|
QStringLiteral("Look for related files in the given resource file"),
|
|
|
|
QStringLiteral("resource"));
|
|
|
|
parser.addOption(resourceOption);
|
2021-05-12 16:32:57 +00:00
|
|
|
const QString &resourceSetting = QLatin1String("ResourcePath");
|
|
|
|
settings.addOption(resourceSetting);
|
2021-02-22 15:12:57 +00:00
|
|
|
|
2020-09-29 14:55:15 +00:00
|
|
|
QCommandLineOption qmlImportPathsOption(
|
2019-06-14 12:21:25 +00:00
|
|
|
QStringList() << "I"
|
|
|
|
<< "qmldirs",
|
2020-09-29 14:55:15 +00:00
|
|
|
QLatin1String("Look for QML modules in specified directory"),
|
2019-06-14 12:21:25 +00:00
|
|
|
QLatin1String("directory"));
|
2020-09-29 14:55:15 +00:00
|
|
|
parser.addOption(qmlImportPathsOption);
|
2021-05-12 16:32:57 +00:00
|
|
|
const QString qmlImportPathsSetting = QLatin1String("AdditionalQmlImportPaths");
|
|
|
|
settings.addOption(qmlImportPathsSetting);
|
2019-06-14 12:21:25 +00:00
|
|
|
|
2021-03-25 11:19:11 +00:00
|
|
|
QCommandLineOption qmlImportNoDefault(
|
|
|
|
QStringList() << "bare",
|
|
|
|
QLatin1String("Do not include default import directories or the current directory. "
|
|
|
|
"This may be used to run qmllint on a project using a different Qt version."));
|
|
|
|
parser.addOption(qmlImportNoDefault);
|
2021-05-12 16:32:57 +00:00
|
|
|
settings.addOption(QLatin1String("DisableDefaultImports"), false);
|
2021-03-25 11:19:11 +00:00
|
|
|
|
2020-03-26 09:57:12 +00:00
|
|
|
QCommandLineOption qmltypesFilesOption(
|
|
|
|
QStringList() << "i"
|
|
|
|
<< "qmltypes",
|
2021-05-12 16:32:57 +00:00
|
|
|
QLatin1String("Import the specified qmltypes files. By default, all qmltypes files "
|
2020-09-29 14:55:15 +00:00
|
|
|
"found in the current directory are used. When this option is set, you "
|
|
|
|
"have to explicitly add files from the current directory if you want "
|
|
|
|
"them to be used."),
|
2020-03-26 09:57:12 +00:00
|
|
|
QLatin1String("qmltypes"));
|
|
|
|
parser.addOption(qmltypesFilesOption);
|
2021-05-12 16:32:57 +00:00
|
|
|
const QString qmltypesFilesSetting = QLatin1String("OverwriteImportTypes");
|
|
|
|
settings.addOption(qmltypesFilesSetting);
|
2020-03-26 09:57:12 +00:00
|
|
|
|
2019-11-11 17:18:04 +00:00
|
|
|
parser.addPositionalArgument(QLatin1String("files"),
|
|
|
|
QLatin1String("list of qml or js files to verify"));
|
2014-07-09 12:28:23 +00:00
|
|
|
|
|
|
|
parser.process(app);
|
|
|
|
|
2021-05-12 16:32:57 +00:00
|
|
|
if (parser.isSet(writeDefaultsOption)) {
|
|
|
|
return settings.writeDefaults() ? 0 : 1;
|
|
|
|
}
|
2021-03-30 10:58:26 +00:00
|
|
|
|
2021-05-12 16:32:57 +00:00
|
|
|
auto updateLogLevels = [&]() {
|
|
|
|
for (auto it = options.begin(); it != options.end(); ++it) {
|
|
|
|
const QString &key = it.key();
|
|
|
|
const QString &settingsName = QStringLiteral("Warnings/") + it.value().m_settingsName;
|
|
|
|
if (parser.isSet(key) || settings.isSet(settingsName)) {
|
|
|
|
const QString value = parser.isSet(key) ? parser.value(key)
|
|
|
|
: settings.value(settingsName).toString();
|
|
|
|
auto &option = it.value();
|
|
|
|
if (!option.setLevel(value)) {
|
|
|
|
qWarning() << "Invalid logging level" << value << "provided for" << it.key()
|
|
|
|
<< "(allowed are: disable, info, warning)";
|
|
|
|
parser.showHelp(-1);
|
|
|
|
}
|
2021-03-30 10:58:26 +00:00
|
|
|
}
|
|
|
|
}
|
2021-05-12 16:32:57 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
updateLogLevels();
|
2021-03-30 10:58:26 +00:00
|
|
|
|
2016-08-11 10:37:27 +00:00
|
|
|
const auto positionalArguments = parser.positionalArguments();
|
|
|
|
if (positionalArguments.isEmpty()) {
|
2014-07-09 12:28:23 +00:00
|
|
|
parser.showHelp(-1);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool silent = parser.isSet(silentOption);
|
2021-06-01 09:03:12 +00:00
|
|
|
bool useJson = parser.isSet(jsonOption);
|
2021-03-30 10:58:26 +00:00
|
|
|
|
2021-03-25 11:19:11 +00:00
|
|
|
// use host qml import path as a sane default if not explicitly disabled
|
|
|
|
QStringList qmlImportPaths = parser.isSet(qmlImportNoDefault)
|
|
|
|
? QStringList {}
|
2021-02-05 17:12:42 +00:00
|
|
|
: QStringList { QLibraryInfo::path(QLibraryInfo::QmlImportsPath), QDir::currentPath() };
|
2020-03-26 09:57:12 +00:00
|
|
|
|
2021-03-25 11:19:11 +00:00
|
|
|
if (parser.isSet(qmlImportPathsOption))
|
|
|
|
qmlImportPaths << parser.values(qmlImportPathsOption);
|
|
|
|
|
2021-05-12 16:32:57 +00:00
|
|
|
qmlImportPaths << settings.value(qmlImportPathsSetting).toStringList();
|
|
|
|
|
2020-09-29 14:55:15 +00:00
|
|
|
QStringList qmltypesFiles;
|
|
|
|
if (parser.isSet(qmltypesFilesOption)) {
|
|
|
|
qmltypesFiles = parser.values(qmltypesFilesOption);
|
2021-05-12 16:32:57 +00:00
|
|
|
} else if (settings.isSet(qmltypesFilesSetting)
|
|
|
|
&& !settings.value(qmltypesFilesSetting).toStringList().isEmpty()) {
|
|
|
|
qmltypesFiles = parser.values(qmltypesFilesSetting);
|
2020-09-29 14:55:15 +00:00
|
|
|
} else {
|
|
|
|
// If none are given explicitly, use the qmltypes files from the current directory.
|
|
|
|
QDirIterator it(".", {"*.qmltypes"}, QDir::Files);
|
2021-01-21 12:55:37 +00:00
|
|
|
while (it.hasNext()) {
|
|
|
|
it.next();
|
2020-09-29 14:55:15 +00:00
|
|
|
qmltypesFiles.append(it.fileInfo().absoluteFilePath());
|
2021-01-21 12:55:37 +00:00
|
|
|
}
|
2020-09-29 14:55:15 +00:00
|
|
|
}
|
2020-03-26 09:57:12 +00:00
|
|
|
|
2021-07-06 07:27:11 +00:00
|
|
|
QStringList resourceFiles;
|
2021-05-12 16:32:57 +00:00
|
|
|
if (parser.isSet(resourceOption))
|
2021-07-06 07:27:11 +00:00
|
|
|
resourceFiles << parser.values(resourceOption);
|
2021-05-12 16:32:57 +00:00
|
|
|
else if (settings.isSet(resourceSetting))
|
2021-07-06 07:27:11 +00:00
|
|
|
resourceFiles << settings.value(resourceSetting).toStringList();
|
2021-02-22 15:12:57 +00:00
|
|
|
|
2017-01-23 08:01:22 +00:00
|
|
|
#else
|
|
|
|
bool silent = false;
|
2021-06-01 09:03:12 +00:00
|
|
|
bool useJson = false;
|
2020-04-24 13:10:53 +00:00
|
|
|
bool warnUnqualified = true;
|
|
|
|
bool warnWithStatement = true;
|
|
|
|
bool warnInheritanceCycle = true;
|
2021-07-06 07:27:11 +00:00
|
|
|
QStringList qmlImportPaths {};
|
2020-09-29 14:55:15 +00:00
|
|
|
QStringList qmltypesFiles {};
|
2021-07-06 07:27:11 +00:00
|
|
|
QStringList resourceFiles {};
|
2017-01-23 08:01:22 +00:00
|
|
|
#endif
|
2014-07-09 12:28:23 +00:00
|
|
|
bool success = true;
|
2021-05-14 15:34:01 +00:00
|
|
|
QQmlJSImporter importer(qmlImportPaths, nullptr);
|
|
|
|
|
2021-06-01 09:03:12 +00:00
|
|
|
QJsonArray jsonFiles;
|
|
|
|
|
2017-01-23 08:01:22 +00:00
|
|
|
#if QT_CONFIG(commandlineparser)
|
2021-05-12 16:32:57 +00:00
|
|
|
for (const QString &filename : positionalArguments) {
|
|
|
|
if (!parser.isSet(ignoreSettings)) {
|
|
|
|
settings.search(filename);
|
|
|
|
updateLogLevels();
|
|
|
|
}
|
2017-01-23 08:01:22 +00:00
|
|
|
#else
|
2017-01-25 23:34:21 +00:00
|
|
|
const auto arguments = app.arguments();
|
2021-05-12 16:32:57 +00:00
|
|
|
for (const QString &filename : arguments) {
|
2017-01-23 08:01:22 +00:00
|
|
|
#endif
|
2021-06-01 09:03:12 +00:00
|
|
|
success &= lint_file(filename, silent, useJson ? &jsonFiles : nullptr, qmlImportPaths,
|
2021-07-06 07:27:11 +00:00
|
|
|
qmltypesFiles, resourceFiles, options, importer);
|
2021-06-01 09:03:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (useJson) {
|
|
|
|
QJsonObject result;
|
|
|
|
|
|
|
|
result[u"revision"_qs] = JSON_LOGGING_FORMAT_REVISION;
|
|
|
|
result[u"files"_qs] = jsonFiles;
|
|
|
|
|
|
|
|
QTextStream(stdout) << QString::fromUtf8(
|
|
|
|
QJsonDocument(result).toJson(QJsonDocument::Compact));
|
2021-05-12 16:32:57 +00:00
|
|
|
}
|
2021-06-01 09:03:12 +00:00
|
|
|
|
2014-07-09 12:28:23 +00:00
|
|
|
return success ? 0 : -1;
|
|
|
|
}
|