aboutsummaryrefslogtreecommitdiffstats
path: root/src/qml/doc/src/tools/qtqml-tooling-qmllint.qdoc
blob: b26fe1eff0101e02ecc4a1525d18c01753d35f53 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// Copyright (C) 2021 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qtqml-tooling-qmllint.html
\title qmllint Reference
\ingroup qtqml-tooling
\brief A tool for verifying the syntax of QML files and warning about
anti-patterns.

\e qmllint is a tool shipped with Qt, that verifies the syntatic validity of
QML files.
It also warns about some QML anti-patterns. If you want to disable a specific
warning type, you can find the appropriate flag for doing so by passing
\c{--help} on the command line.

By default, some issues will result in warnings that will be printed and result
in a non-zero exit code.
Minor issues however (such as unused imports) are just informational messages
by default and will not affect the exit code.
qmllint is very configurable and allows for disabling warnings or changing how
they are treated.
Users may freely turn any issue into a warning, informational message, or
disable them outright.

qmllint warns about:
\list
  \li Unqualified accesses of properties
  \li Usage of signal handlers without a matching signal
  \li Usage of with statements in QML
  \li Issues related to compiling QML code
  \li Unused imports
  \li Deprecated components and properties
  \li And many other things
\endlist

\note In order for qmllint to work properly, it requires type information.
That information is provided by QML modules in the import paths.
The current directory, as well as the import paths for Qt's built-in types,
are used as import paths by default.
To add more import paths not included in the default,
add them via the \c{-I} flag.

To get an overview and explanation of all available command line options, run \c{qmllint --help}.

\section2 Compiler warnings

qmllint can warn you about code that cannot be compiled by \l{qmlsc}.

These warnings are not enabled by default. In order to enable them specify
\c{--compiler warning} or adjust your settings file accordingly.

\section2 Marking components and properties as deprecated

qmllint allows you to mark both properties and components as deprecated:

\code
@Deprecated { reason: "Use NewCustomText instead" }
Text {
    @Deprecated { reason: "Use newProperty instead" }
    property int oldProperty
    property int newProperty
    Component.onCompleted: console.log(oldProperty);  // Warning: XY.qml:8:40: Property "oldProperty" is deprecated (Reason: Use newProperty instead)
}
\endcode

Deprecation warnings for components will be shown every time the component is created.

\section2 Disabling warnings inline

You may at any point disable warnings temporarily in a file using \c{// qmllint
disable}.

You can do this at the end of a line when a single line produces warnings:

\code
Item {
    property string foo
    Item {
        property string bar: foo // qmllint disable unqualified
    }
}
\endcode

Alternatively you can disable comments for a block of lines by putting the
comment in a line only containing \c{// qmllint disable}, ending the block with
\c{// qmllint enable}:

\code
Item {
    property string foo
    Item {
        // qmllint disable unqualified
        property string bar: foo
        property string bar2: foo
        // qmllint enable unqualified
    }
}
\endcode

qmllint interprets all single line comments starting with \c {qmllint} as
directives. Thus you may not start a comment that way unless you wish to enable
or disable warnings.

\note As done in the examples above it is preferable to explicitly specify the
warning or a list of warnings you want to disable instead of disabling all
warnings. This can be done by simply listing warning categories after \c{qmllint disable} (the names are
the same as the options listed in \c{--help}).

\section2 Settings

In addition to passing command-line options, you can also
configure qmllint via a settings file.
The command line \c{--write-defaults} will generate one for you.

Setting files are named \c{.qmllint.ini} and look like this:

\quotefile qmllint/config.ini

Warning levels may be set to \c{info}, \c{warning} or \c{disable} just as with
command line options.

qmllint will automatically look for a settings file at the location of the qml
file that is being linted.
It also looks through all parent directories to find this file and
automatically applies the settings therein. You can disable this behavior by
using \c{--ignore-settings}.
You may always override these defaults by specifying command line parameters
that take precedence over the warning levels in settings.

\section2 Scripting

qmllint can write or output JSON via the \c{--json <file>} option which will return valid JSON
with warning messages, file and line location of warnings, and their severity
level. Use the special filename '-' to write to stdout instead of a file.
This can be used to more easily integrate qmllint in your pre-commit hooks or
CI testing.

\sa {Type Description Files}
\sa {Qt Quick Tools and Utilities}
*/