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
quicklintplugin.h
Go to the documentation of this file.
1// Copyright (C) 2022 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 reason:default
4
5#ifndef QUICKLINTPLUGIN_H
6#define QUICKLINTPLUGIN_H
7
8#include <QtCore/qplugin.h>
9#include <QtCore/qlist.h>
10#include <QtCore/qvarlengtharray.h>
11#include <QtCore/qhash.h>
12
13#include <QtQmlCompiler/qqmlsa.h>
15
17
23
25{
26 Q_OBJECT
27 Q_PLUGIN_METADATA(IID QmlLintPluginInterface_iid FILE "plugin.json")
29
30public:
32};
33
35{
36public:
37 ForbiddenChildrenPropertyValidatorPass(QQmlSA::PassManager *manager);
38
39 void addWarning(QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName,
40 QAnyStringView warning);
41 bool shouldRun(const QQmlSA::Element &element) override;
42 void run(const QQmlSA::Element &element) override;
43
44private:
45 struct Warning
46 {
47 QString propertyName;
48 QString message;
49 };
50
52};
53
55{
56public:
57 AttachedPropertyTypeValidatorPass(QQmlSA::PassManager *manager);
58
59 QString addWarning(TypeDescription attachType, QList<TypeDescription> allowedTypes,
60 bool allowInDelegate, QAnyStringView warning);
61
62 void onBinding(const QQmlSA::Element &element, const QString &propertyName,
63 const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope,
64 const QQmlSA::Element &value) override;
65 void onRead(const QQmlSA::Element &element, const QString &propertyName,
66 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override;
67 void onWrite(const QQmlSA::Element &element, const QString &propertyName,
68 const QQmlSA::Element &value, const QQmlSA::Element &writeScope,
69 QQmlSA::SourceLocation location) override;
70
71private:
72 void checkWarnings(const QQmlSA::Element &element, const QQmlSA::Element &scopeUsedIn,
73 const QQmlSA::SourceLocation &location);
74
75 struct Warning
76 {
77 QVarLengthArray<QQmlSA::Element, 4> allowedTypes;
78 bool allowInDelegate = false;
79 QString message;
80 };
81 QHash<QString, Warning> m_attachedTypes;
82};
83
85{
86public:
87 ControlsNativeValidatorPass(QQmlSA::PassManager *manager);
88
89 bool shouldRun(const QQmlSA::Element &element) override;
90 void run(const QQmlSA::Element &element) override;
91
92private:
93 struct ControlElement
94 {
95 QString name;
96 QStringList restrictedProperties;
97 bool isInModuleControls = true;
98 bool isControl = false;
99 bool inheritsControl = false;
100 QQmlSA::Element element = {};
101 };
102
103 QList<ControlElement> m_elements;
104};
105
107{
108public:
109 AnchorsValidatorPass(QQmlSA::PassManager *manager);
110
111 bool shouldRun(const QQmlSA::Element &element) override;
112 void run(const QQmlSA::Element &element) override;
113
114private:
115 QQmlSA::Element m_item;
116};
117
119{
120public:
121 ControlsSwipeDelegateValidatorPass(QQmlSA::PassManager *manager);
122
123 bool shouldRun(const QQmlSA::Element &element) override;
124 void run(const QQmlSA::Element &element) override;
125
126private:
127 QQmlSA::Element m_swipeDelegate;
128};
129
131{
132public:
133 VarBindingTypeValidatorPass(QQmlSA::PassManager *manager,
134 const QMultiHash<QString, TypeDescription> &expectedPropertyTypes);
135
136 void onBinding(const QQmlSA::Element &element, const QString &propertyName,
137 const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope,
138 const QQmlSA::Element &value) override;
139
140private:
141 QMultiHash<QString, QQmlSA::Element> m_expectedPropertyTypes;
142};
143
145{
146public:
147 PropertyChangesValidatorPass(QQmlSA::PassManager *manager);
148
149 bool shouldRun(const QQmlSA::Element &element) override;
150 void run(const QQmlSA::Element &element) override;
151
152private:
153 QQmlSA::Element m_propertyChanges;
154};
155
157{
158public:
163
164 AttachedPropertyReuse(QQmlSA::PassManager *manager, QQmlSA::LoggerWarningId category)
166 {}
167
168 void onRead(const QQmlSA::Element &element, const QString &propertyName,
169 const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override;
170 void onWrite(const QQmlSA::Element &element, const QString &propertyName,
171 const QQmlSA::Element &value, const QQmlSA::Element &writeScope,
172 QQmlSA::SourceLocation location) override;
173
174private:
175 struct ElementAndLocation {
176 QQmlSA::Element element;
177 QQmlSA::SourceLocation location;
178 };
179
180 QMultiHash<QQmlSA::Element, ElementAndLocation> usedAttachedTypes;
181 QQmlSA::LoggerWarningId category;
182};
183
185{
186public:
187 StateNoItemChildrenValidator(QQmlSA::PassManager *manager);
188
189 bool shouldRun(const QQmlSA::Element &element) override;
190 void run(const QQmlSA::Element &element) override;
191
192private:
193 QQmlSA::Element m_state;
194 QQmlSA::Element m_anchorChanges;
195 QQmlSA::Element m_parentChanges;
196 QQmlSA::Element m_propertyChanges;
197 QQmlSA::Element m_stateChangeScript;
198};
199
200QT_END_NAMESPACE
201
202#endif // QUICKLINTPLUGIN_H
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
AnchorsValidatorPass(QQmlSA::PassManager *manager)
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
void onRead(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override
Executes whenever a property is read.
AttachedPropertyReuse(QQmlSA::PassManager *manager, QQmlSA::LoggerWarningId category)
void onWrite(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &value, const QQmlSA::Element &writeScope, QQmlSA::SourceLocation location) override
Executes whenever a property is written to.
void onRead(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &readScope, QQmlSA::SourceLocation location) override
Executes whenever a property is read.
AttachedPropertyTypeValidatorPass(QQmlSA::PassManager *manager)
void onWrite(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Element &value, const QQmlSA::Element &writeScope, QQmlSA::SourceLocation location) override
Executes whenever a property is written to.
void onBinding(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope, const QQmlSA::Element &value) override
Executes whenever a property gets bound to a value.
QString addWarning(TypeDescription attachType, QList< TypeDescription > allowedTypes, bool allowInDelegate, QAnyStringView warning)
ColorValidatorPass(QQmlSA::PassManager *manager)
void onBinding(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope, const QQmlSA::Element &value) override
Executes whenever a property gets bound to a value.
ControlsNativeValidatorPass(QQmlSA::PassManager *manager)
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
ControlsSwipeDelegateValidatorPass(QQmlSA::PassManager *manager)
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
void addWarning(QAnyStringView moduleName, QAnyStringView typeName, QAnyStringView propertyName, QAnyStringView warning)
ForbiddenChildrenPropertyValidatorPass(QQmlSA::PassManager *manager)
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
PropertyChangesValidatorPass(QQmlSA::PassManager *manager)
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
void run(const QQmlSA::Element &element) override
Executes if shouldRun() returns true.
StateNoItemChildrenValidator(QQmlSA::PassManager *manager)
bool shouldRun(const QQmlSA::Element &element) override
Controls whether the run() function should be executed on the given element.
VarBindingTypeValidatorPass(QQmlSA::PassManager *manager, const QMultiHash< QString, TypeDescription > &expectedPropertyTypes)
void onBinding(const QQmlSA::Element &element, const QString &propertyName, const QQmlSA::Binding &binding, const QQmlSA::Element &bindingScope, const QQmlSA::Element &value) override
Executes whenever a property gets bound to a value.
\inmodule QtQmlCompiler
static constexpr QQmlSA::LoggerWarningId quickControlsAttachedPropertyReuse
static constexpr QQmlSA::LoggerWarningId quickControlsNativeCustomize
static constexpr QQmlSA::LoggerWarningId quickStateNoChildItem
static constexpr QQmlSA::LoggerWarningId quickAttachedPropertyType
static constexpr QQmlSA::LoggerWarningId quickUnexpectedVarType
static constexpr QQmlSA::LoggerWarningId quickAttachedPropertyReuse
static constexpr QQmlSA::LoggerWarningId quickPropertyChangesParsed
static constexpr QQmlSA::LoggerWarningId quickAnchorCombinations
static constexpr QQmlSA::LoggerWarningId quickLayoutPositioning
static constexpr QQmlSA::LoggerWarningId quickColor