aboutsummaryrefslogtreecommitdiffstats
path: root/tools/qmllint
diff options
context:
space:
mode:
authorMaximilian Goldstein <max.goldstein@qt.io>2021-08-02 16:50:27 +0200
committerMaximilian Goldstein <max.goldstein@qt.io>2021-08-04 17:15:22 +0200
commitef075016527c48f6ec64c088edb400ab52211d75 (patch)
tree7f33ce9b18ae1ef22cc00c2b8d7c43f45885e277 /tools/qmllint
parent283816d07dee9afaa9fa183b9102076f32568449 (diff)
qmllint: Move use-before-declaration warning out of checkidentifiers
Another step to making checkidentifiers obsolete. Change-Id: I14be7491387200101b66e0930faf16e9b61d4159 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Diffstat (limited to 'tools/qmllint')
-rw-r--r--tools/qmllint/CMakeLists.txt1
-rw-r--r--tools/qmllint/checkidentifiers.cpp14
-rw-r--r--tools/qmllint/codegenwarninginterface.cpp44
-rw-r--r--tools/qmllint/codegenwarninginterface.h48
-rw-r--r--tools/qmllint/main.cpp4
5 files changed, 96 insertions, 15 deletions
diff --git a/tools/qmllint/CMakeLists.txt b/tools/qmllint/CMakeLists.txt
index 2226e5cd81..fdfe0e4b2c 100644
--- a/tools/qmllint/CMakeLists.txt
+++ b/tools/qmllint/CMakeLists.txt
@@ -12,6 +12,7 @@ qt_internal_add_tool(${target_name}
checkidentifiers.cpp checkidentifiers.h
findwarnings.cpp findwarnings.h
codegen.cpp codegen.h
+ codegenwarninginterface.cpp codegenwarninginterface.h
main.cpp
../shared/qqmltoolingsettings.h
../shared/qqmltoolingsettings.cpp
diff --git a/tools/qmllint/checkidentifiers.cpp b/tools/qmllint/checkidentifiers.cpp
index a22cf7a8e5..d1b461a5ff 100644
--- a/tools/qmllint/checkidentifiers.cpp
+++ b/tools/qmllint/checkidentifiers.cpp
@@ -209,20 +209,6 @@ void CheckIdentifiers::operator()(
continue;
auto memberAccessBase = memberAccessChain.takeFirst();
- const auto jsId = currentScope->findJSIdentifier(memberAccessBase.m_name);
- if (jsId.has_value() && jsId->kind != QQmlJSScope::JavaScriptIdentifier::Injected) {
- if (memberAccessBase.m_location.end() < jsId->location.begin()) {
- // TODO: Is there a more fitting category?
- m_logger->logWarning(
- QStringLiteral("Variable \"%1\" is used here before its declaration. "
- "The declaration is at %4:%5.")
- .arg(memberAccessBase.m_name)
- .arg(jsId->location.startLine)
- .arg(jsId->location.startColumn),
- Log_Type, memberAccessBase.m_location);
- }
- continue;
- }
auto it = qmlIDs.find(memberAccessBase.m_name);
if (it != qmlIDs.end()) {
diff --git a/tools/qmllint/codegenwarninginterface.cpp b/tools/qmllint/codegenwarninginterface.cpp
new file mode 100644
index 0000000000..11e39abbb0
--- /dev/null
+++ b/tools/qmllint/codegenwarninginterface.cpp
@@ -0,0 +1,44 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#include "codegenwarninginterface.h"
+
+#include <QtQmlCompiler/private/qqmljslogger_p.h>
+
+void CodegenWarningInterface::reportVarUsedBeforeDeclaration(
+ const QString &name, const QString &fileName, QQmlJS::SourceLocation declarationLocation,
+ QQmlJS::SourceLocation accessLocation)
+{
+ Q_UNUSED(fileName)
+ m_logger->logWarning(
+ u"Variable \"%1\" is used here before its declaration. The declaration is at %2:%3."_qs
+ .arg(name)
+ .arg(declarationLocation.startLine)
+ .arg(declarationLocation.startColumn),
+ Log_Type, accessLocation);
+}
diff --git a/tools/qmllint/codegenwarninginterface.h b/tools/qmllint/codegenwarninginterface.h
new file mode 100644
index 0000000000..3899ff7d53
--- /dev/null
+++ b/tools/qmllint/codegenwarninginterface.h
@@ -0,0 +1,48 @@
+/****************************************************************************
+**
+** Copyright (C) 2021 The Qt Company Ltd.
+** Contact: https://www.qt.io/licensing/
+**
+** This file is part of the tools applications of the Qt Toolkit.
+**
+** $QT_BEGIN_LICENSE:GPL-EXCEPT$
+** 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
+** a written agreement between you and The Qt Company. For licensing terms
+** and conditions see https://www.qt.io/terms-conditions. For further
+** information use the contact form at https://www.qt.io/contact-us.
+**
+** 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.
+**
+** $QT_END_LICENSE$
+**
+****************************************************************************/
+
+#ifndef CODEGENWARNINGINTERFACE_H
+#define CODEGENWARNINGINTERFACE_H
+
+#include <QtQml/private/qv4codegen_p.h>
+
+class QQmlJSLogger;
+class CodegenWarningInterface final : public QV4::Compiler::CodegenWarningInterface
+{
+public:
+ CodegenWarningInterface(QQmlJSLogger *logger) : m_logger(logger) { }
+
+ void reportVarUsedBeforeDeclaration(const QString &name, const QString &fileName,
+ QQmlJS::SourceLocation declarationLocation,
+ QQmlJS::SourceLocation accessLocation) override;
+
+private:
+ QQmlJSLogger *m_logger;
+};
+
+#endif // CODEGENWARNINGINTERFACE_H
diff --git a/tools/qmllint/main.cpp b/tools/qmllint/main.cpp
index fba020cd6c..ee16409f4e 100644
--- a/tools/qmllint/main.cpp
+++ b/tools/qmllint/main.cpp
@@ -28,6 +28,7 @@
#include "findwarnings.h"
#include "codegen.h"
+#include "codegenwarninginterface.h"
#include "../shared/qqmltoolingsettings.h"
#include <QtQmlCompiler/private/qqmljsresourcefilemapper_p.h>
@@ -190,7 +191,8 @@ static bool lint_file(const QString &filename, const bool silent, QJsonArray *js
QLoggingCategory::setFilterRules(u"qt.qml.compiler=false"_qs);
- qCompileQmlFile(filename, saveFunction, &codegen, &error, true);
+ CodegenWarningInterface interface(&v.logger());
+ qCompileQmlFile(filename, saveFunction, &codegen, &error, true, &interface);
success &= !v.logger().hasWarnings() && !v.logger().hasErrors();