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
qtqml-tooling-qmllint.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2021 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\page qtqml-tooling-qmllint.html
6
\title qmllint
7
\keyword qmllint Reference
8
\ingroup qtqml-tooling
9
\ingroup qtqml-tooling-devtools
10
\brief A tool for verifying the syntax of QML files and warning about
11
anti-patterns.
12
13
\e qmllint is a tool shipped with Qt, that verifies the syntatic validity of
14
QML files. You can \l{Using qmllint with CMake}{integrate qmllint into your build system}
15
for ease of use. It also warns about some QML anti-patterns. If you want to
16
disable a specific warning type, you can find the appropriate flag for doing so
17
by passing \c{--help} on the command line.
18
19
By default, some issues will result in warnings that will be printed. If there
20
are more warnings than a limit which can be configured with \c{--max-warnings},
21
the exit code will be non-zero.
22
Minor issues however (such as unused imports) are just informational messages
23
by default and will never affect the exit code.
24
qmllint is very configurable and allows for disabling warnings or changing how
25
they are treated.
26
Users may freely turn any issue into a warning, informational message, or
27
disable them outright.
28
29
qmllint warns about:
30
\list
31
\li Unqualified accesses of properties
32
\li Usage of signal handlers without a matching signal
33
\li Usage of with statements in QML
34
\li Issues related to compiling QML code
35
\li Unused imports
36
\li Deprecated components and properties
37
\li And many other things
38
\endlist
39
40
See \l{QML Lint Warning and Errors} on how to fix qmllint warnings and errors.
41
42
\note In order for qmllint to work properly, it requires type information.
43
That information is provided by QML modules in the import paths.
44
The current directory, as well as the import paths for Qt's built-in types,
45
are used as import paths by default.
46
To add more import paths not included in the default,
47
add them via the \c{-I} flag.
48
49
To get an overview and explanation of all available command line options, run \c{qmllint --help}.
50
51
\section2 Compiler warnings
52
53
qmllint can warn you about code that cannot be compiled by \l{qmlsc}.
54
55
These warnings are not enabled by default. In order to enable them specify
56
\c{--compiler warning} or adjust your settings file accordingly.
57
58
\section2 Using qmllint with CMake
59
For projects using the \l{qt6_add_qml_module}{qt_add_qml_module()} CMake API for creating QML
60
modules, \l{Linting QML sources}{convenience targets} such as \c all_qmllint are created
61
automatically. These run qmllint on all the QML files of a specific module or of the project.
62
63
\section2 Marking components and properties as deprecated
64
65
qmllint allows you to mark both properties and components as deprecated:
66
67
\code
68
@Deprecated { reason: "Use NewCustomText instead" }
69
Text {
70
@Deprecated { reason: "Use newProperty instead" }
71
property int oldProperty
72
property int newProperty
73
Component.onCompleted: console.log(oldProperty); // Warning: XY.qml:8:40: Property "oldProperty" is deprecated (Reason: Use newProperty instead)
74
}
75
\endcode
76
77
Deprecation warnings for components will be shown every time the component is created.
78
79
\section2 Disabling warnings inline
80
81
You may at any point disable warnings temporarily in a file using \c{// qmllint
82
disable}.
83
84
You can do this at the end of a line when a single line produces warnings:
85
86
\code
87
Item {
88
property string foo
89
Item {
90
property string bar: foo // qmllint disable unqualified
91
}
92
}
93
\endcode
94
95
Alternatively you can disable comments for a block of lines by putting the
96
comment in a line only containing \c{// qmllint disable}, ending the block with
97
\c{// qmllint enable}:
98
99
\code
100
Item {
101
property string foo
102
Item {
103
// qmllint disable unqualified
104
property string bar: foo
105
property string bar2: foo
106
// qmllint enable unqualified
107
}
108
}
109
\endcode
110
111
qmllint interprets all single line comments starting with \c {qmllint} as
112
directives. Thus you may not start a comment that way unless you wish to enable
113
or disable warnings.
114
115
\note As done in the examples above it is preferable to explicitly specify the
116
warning or a list of warnings you want to disable instead of disabling all
117
warnings. This can be done by simply listing warning categories after \c{qmllint disable} (the names are
118
the same as the options listed in \c{--help}).
119
120
\section2 Settings
121
122
In addition to passing command-line options, you can also
123
configure qmllint via a settings file.
124
The command line \c{--write-defaults} will generate one for you.
125
126
Setting files are named \c{.qmllint.ini} and look like this:
127
128
\quotefile qmllint/config.ini
129
130
Warning levels may be set to \c{info}, \c{warning} or \c{disable} just as with
131
command line options.
132
133
qmllint will automatically look for a settings file at the location of the qml
134
file that is being linted.
135
It also looks through all parent directories to find this file and
136
automatically applies the settings therein. You can disable this behavior by
137
using \c{--ignore-settings}.
138
You may always override these defaults by specifying command line parameters
139
that take precedence over the warning levels in settings.
140
141
\section3 Context property settings
142
143
Context properties can be defined or ignored by name in their own settings file.
144
Context property settings allow a more fine-grained approach to disabling unqualified
145
access warnings for context property usages, while \c{.qmllint.ini} only allows to
146
disable all unqualified access warnings, potentially including non-context property
147
related ones.
148
149
Context property settings are named \c{.contextProperties.ini} and look like this:
150
151
\quotefile qmllint/contextProperties.ini
152
153
To disable qmllint warnings about unqualified access to a context property name,
154
add the context property name to \c{disableUnqualifiedAccess}.
155
156
To warn about context property usages, add the context property name to \c{warnOnUsage}.
157
158
To control the qmllint heuristic, set \c{disableHeuristic} to \c{true} or \c{false}.
159
160
\section2 Scripting
161
162
qmllint can write or output JSON via the \c{--json <file>} option which will return valid JSON
163
with warning messages, file and line location of warnings, and their severity
164
level. Use the special filename '-' to write to stdout instead of a file.
165
This can be used to more easily integrate qmllint in your pre-commit hooks or
166
CI testing.
167
168
\sa {Type Description Files}
169
\sa {Qt Quick Tools and Utilities}
170
*/
qtdeclarative
src
qml
doc
src
tools
qtqml-tooling-qmllint.qdoc
Generated on
for Qt by
1.14.0