1// Copyright (C) 2021 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qtquick-tool-qmllint.html
7\brief A tool for verifying the syntax of QML files and warning about
10\e qmllint is a tool shipped with Qt, that verifies the syntatic validity of
12It also warns about some QML anti-patterns. If you want to disable a specific
13warning type, you can find the appropriate flag for doing so by passing
14\c{--help} on the command line.
16By default, some issues will result in warnings that will be printed and result
17in a non-zero exit code.
18Minor issues however (such as unused imports) are just informational messages
19by default and will not affect the exit code.
20qmllint is very configurable and allows for disabling warnings or changing how
22Users may freely turn any issue into a warning, informational message, or
27 \li Unqualified accesses of properties
28 \li Usage of signal handlers without a matching signal
29 \li Usage of with statements in QML
30 \li Issues related to compiling QML code
32 \li Deprecated components and properties
33 \li And many other things
36\note In order for qmllint to work properly, it requires type information.
37That information is provided by QML modules in the import paths.
38The current directory, as well as the import paths for Qt's built-in types,
39are used as import paths by default.
40To add more import paths not included in the default,
41add them via the \c{-I} flag.
43To get an overview and explanation of all available command line options, run \c{qmllint --help}.
45\section2 Compiler warnings
47qmllint can warn you about code that cannot be compiled by \l{qmlsc}.
49These warnings are not enabled by default. In order to enable them specify
50\c{--compiler warning} or adjust your settings file accordingly.
52\section2 Marking components and properties as deprecated
54qmllint allows you to mark both properties and components as deprecated:
57@Deprecated { reason: "Use NewCustomText instead" }
59 @Deprecated { reason: "Use newProperty instead" }
60 property int oldProperty
61 property int newProperty
62 Component.onCompleted: console.log(oldProperty); // Warning: XY.qml:8:40: Property "oldProperty" is deprecated (Reason: Use newProperty instead)
66Deprecation warnings for components will be shown every time the component is created.
68\section2 Disabling warnings inline
70You may at any point disable warnings temporarily in a file using \c{// qmllint
73You can do this at the end of a line when a single line produces warnings:
79 property string bar: foo // qmllint disable unqualified
84Alternatively you can disable comments for a block of lines by putting the
85comment in a line only containing \c{// qmllint disable}, ending the block with
92 // qmllint disable unqualified
93 property string bar: foo
94 property string bar2: foo
95 // qmllint enable unqualified
100qmllint interprets all single line comments starting with \c {qmllint} as
101directives. Thus you may not start a comment that way unless you wish to enable
104\note As done in the examples above it is preferable to explicitly specify the
105warning or a list of warnings you want to disable instead of disabling all
106warnings. This can be done by simply listing warning categories after \c{qmllint disable} (the names are
107the same as the options listed in \c{--help}).
111In addition to passing command-line options, you can also
112configure qmllint via a settings file.
113The command line \c{--write-defaults} will generate one for you.
115Setting files are named \c{.qmllint.ini} and look like this:
117\quotefile qmllint/config.ini
119Warning levels may be set to \c{info}, \c{warning} or \c{disable} just as with
122qmllint will automatically look for a settings file at the location of the qml
123file that is being linted.
124It also looks through all parent directories to find this file and
125automatically applies the settings therein. You can disable this behavior by
126using \c{--ignore-settings}.
127You may always override these defaults by specifying command line parameters
128that take precedence over the warning levels in settings.
132qmllint can write or output JSON via the \c{--json <file>} option which will return valid JSON
133with warning messages, file and line location of warnings, and their severity
134level. Use the special filename '-' to write to stdout instead of a file.
135This can be used to more easily integrate qmllint in your pre-commit hooks or
138\sa {Type Description Files}
139\sa {Qt Quick Tools and Utilities}