1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
5\page qtqml-tooling-qmlformat.html
7\brief Overview of the qmlformat tool.
11\e qmlformat is a tool that automatically formats QML files in accordance
12with the \l{QML Coding Conventions}. \l{Details}{More...}
18 \li qmlformat [\l{options}] \l{arguments}
23The following options are available:
33 \li Displays help on commandline options.
37 \li Displays help, including generic Qt options.
42 \li Displays version information.
46 \li Verbose mode. Outputs more detailed information.
50 \li Writes defaults settings to .qmlformat.ini and exits
51 (Warning: This will overwrite any existing settings and comments!)
55 \li Ignores all settings files and only takes command line options into consideration
59 \li Edit file in-place instead of outputting to stdout.
63 \li Continue even if an error has occurred.
67 \li Use tabs instead of spaces.
69 \li -w, --indent-width <width>
71 \li How many spaces are used when indenting.
75 \li Reorders the attributes of the objects according to the QML Coding Guidelines.
77 \li -F, --files <file>
79 \li Format all files listed in file, in-place
81 \li -l, --newline <newline>
83 \li Override the new line format to use (native macos unix windows).
87 \li Ensure spaces between objects (only works with normalize option).
89 \li --functions-spacing
91 \li Ensure spaces between functions (only works with normalize option).
105\e qmlformat is flexible and can be configured according to your needs.
108qmlformat writes the formatted version of the file to stdout.
109If you wish to have your file updated in-place specify the \c{-i} flag.
111\section3 Grouping Properties, Functions, and Signals Together
112With \c{-n} or \c{--normalize} flag, \e qmlformat groups all properties, functions,
113and signals together, instead of retaining the order you specified.
115\section3 Settings File
116You can configure \e qmlformat by including a settings file \c{.qmlformat.ini} in your
117project source or in the parent directories of your project source folder. A default
118settings file can be obtained by passing the \c{--write-defaults} flag. This generates the
119\c{.qmlformat.ini} file in the current working directory.
121\warning \c{--write-defaults} will overwrite any existing settings and comments!
123\section3 Formatting a List of Files
124While you can pass a list of files to be formatted as arguments, qmlformat provides
125\c {-F} option to format a set of files stored in a file. In this case, formatting will happen
136 qmlformat -F FileList.txt
139\note If the file contains an invalid entry, for example, a file path that
140doesn't exist or a valid file path but the content is an invalid qml document,
141then \c qmlformat will error out for that particular entry. It will still format
142the valid file entries in place.
144\warning If you provide -F option, qmlformat will ignore the positional arguments.