Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qqmljslintervisitor_p.h
Go to the documentation of this file.
1// Copyright (C) 2025 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
3// Qt-Security score:significant
4
5#ifndef QQMLJSLINTERVISITOR_P_H
6#define QQMLJSLINTERVISITOR_P_H
7
8//
9// W A R N I N G
10// -------------
11//
12// This file is not part of the Qt API. It exists purely as an
13// implementation detail. This header file may change from version to
14// version without notice, or even be removed.
15//
16// We mean it.
17
18#include <private/qqmljsimportvisitor_p.h>
19
20#include <private/qqmljsengine_p.h>
21
22QT_BEGIN_NAMESPACE
23
24namespace QQmlJS {
25
26/*!
27 \internal
28 Extends QQmlJSImportVisitor with extra warnings that are required for linting but unrelated to
29 QQmlJSImportVisitor actual task that is constructing QQmlJSScopes. One example of such warnings
30 are purely syntactic checks, or warnings that don't affect compilation.
31 */
32class LinterVisitor final : public QQmlJSImportVisitor
33{
34public:
35 LinterVisitor(QQmlJSImporter *importer, QQmlJSLogger *logger,
36 const QString &implicitImportDirectory,
37 const QStringList &qmldirFiles = QStringList(), QQmlJS::Engine *engine = nullptr);
38
39protected:
40 using QQmlJSImportVisitor::endVisit;
41 using QQmlJSImportVisitor::visit;
42
43 bool preVisit(QQmlJS::AST::Node *) override;
44 void postVisit(QQmlJS::AST::Node *) override;
46
48
49 bool visit(QQmlJS::AST::StringLiteral *) override;
50 bool visit(AST::CommaExpression *) override;
51 bool visit(QQmlJS::AST::NewMemberExpression *) override;
52 bool visit(QQmlJS::AST::VoidExpression *ast) override;
53 bool visit(QQmlJS::AST::BinaryExpression *) override;
54 bool visit(QQmlJS::AST::UiImport *import) override;
55 bool visit(QQmlJS::AST::UiEnumDeclaration *uied) override;
56 bool visit(QQmlJS::AST::CaseBlock *) override;
57 bool visit(QQmlJS::AST::ExpressionStatement *ast) override;
58
59private:
60 struct SeenImport
61 {
62 QStringView filename;
63 QString uri;
64 QTypeRevision version;
65 QStringView id;
66 QQmlJS::AST::UiImport *uiImport;
67
68 SeenImport(QQmlJS::AST::UiImport *i) : filename(i->fileName), id(i->importId), uiImport(i)
69 {
70 if (i->importUri)
71 uri = i->importUri->toString();
72 if (i->version)
73 version = i->version->version;
74 }
75 friend bool comparesEqual(const SeenImport &lhs, const SeenImport &rhs) noexcept
76 {
77 return lhs.filename == rhs.filename && lhs.uri == rhs.uri
78 && lhs.version == rhs.version && lhs.id == rhs.id;
79 }
80 Q_DECLARE_EQUALITY_COMPARABLE(SeenImport)
81
82 friend size_t qHash(const SeenImport &i, size_t seed = 0)
83 {
84 return qHashMulti(seed, i.filename, i.uri, i.version, i.id);
85 }
86 };
87 QQmlJS::Engine *m_engine = nullptr;
88 QSet<SeenImport> m_seenImports;
89 std::vector<QQmlJS::AST::Node *> m_ancestryIncludingCurrentNode;
90
91 void handleDuplicateEnums(QQmlJS::AST::UiEnumMemberList *members, QStringView key,
92 const QQmlJS::SourceLocation &location);
93 void warnCaseNoFlowControl(QQmlJS::SourceLocation caseToken) const;
94 void checkCaseFallthrough(QQmlJS::AST::StatementList *statements, SourceLocation errorLoc,
95 SourceLocation nextLoc);
97 const QString &name, const QQmlJS::AST::Statement *statement,
98 const QQmlJS::AST::UiPublicMember *associatedPropertyDefinition = nullptr) override;
99 void handleLiteralBinding(const QQmlJSMetaPropertyBinding &binding,
100 const AST::UiPublicMember *associatedPropertyDefinition) override;
101};
102
103} // namespace QQmlJS
104
105QT_END_NAMESPACE
106
107#endif // QQMLJSLINTERVISITOR_P_H
void postVisit(QQmlJS::AST::Node *) override
void handleLiteralBinding(const QQmlJSMetaPropertyBinding &binding, const AST::UiPublicMember *associatedPropertyDefinition) override
LinterVisitor(QQmlJSImporter *importer, QQmlJSLogger *logger, const QString &implicitImportDirectory, const QStringList &qmldirFiles=QStringList(), QQmlJS::Engine *engine=nullptr)
BindingExpressionParseResult parseBindingExpression(const QString &name, const QQmlJS::AST::Statement *statement, const QQmlJS::AST::UiPublicMember *associatedPropertyDefinition=nullptr) override
bool visit(QQmlJS::AST::StringLiteral *) override
QQmlJS::AST::Node * astParentOfVisitedNode() const
bool preVisit(QQmlJS::AST::Node *) override
static bool isUselessExpressionStatement(ExpressionNode *ast)
static void warnAboutLiteralConstructors(NewMemberExpression *expression, QQmlJSLogger *logger)
static SourceLocation confusingPluses(BinaryExpression *exp)
static bool allCodePathsReturnInsideCase(Node *statement)
static SourceLocation confusingMinuses(BinaryExpression *exp)
static bool canHaveUselessExpressionStatement(Node *parent)