Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtqml-tooling-qmlformat.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtqml-tooling-qmlformat.html
6\title qmlformat
7\brief Overview of the qmlformat tool.
8\ingroup qtqml-tooling
9
10\section1 qmlformat
11\e qmlformat is a tool that automatically formats QML files in accordance
12with the \l{QML Coding Conventions}. \l{Details}{More...}
13
14\table
15\header
16 \li Usage:
17\row
18 \li qmlformat [\l{options}] \l{arguments}
19\endtable
20
21\section2 Options
22\target options
23The following options are available:
24
25\table
26\header
27 \li Option
28 \li Default Value
29 \li Description
30\row
31 \li -h, --help
32 \li
33 \li Displays help on commandline options.
34\row
35 \li --help-all
36 \li
37 \li Displays help, including generic Qt options.
38
39\row
40 \li -v, --version
41 \li
42 \li Displays version information.
43\row
44 \li -V, --verbose
45 \li
46 \li Verbose mode. Outputs more detailed information.
47\row
48 \li --write-defaults
49 \li
50 \li Writes defaults settings to .qmlformat.ini and exits
51 (Warning: This will overwrite any existing settings and comments!)
52\row
53 \li --ignore-settings
54 \li
55 \li Ignores all settings files and only takes command line options into consideration
56\row
57 \li -i, --inplace
58 \li
59 \li Edit file in-place instead of outputting to stdout.
60\row
61 \li -f, --force
62 \li
63 \li Continue even if an error has occurred.
64\row
65 \li -t, --tabs
66 \li
67 \li Use tabs instead of spaces.
68\row
69 \li -w, --indent-width <width>
70 \li 4
71 \li How many spaces are used when indenting.
72\row
73 \li -n, --normalize
74 \li
75 \li Reorders the attributes of the objects according to the QML Coding Guidelines.
76\row
77 \li -F, --files <file>
78 \li
79 \li Format all files listed in file, in-place
80\row
81 \li -l, --newline <newline>
82 \li
83 \li Override the new line format to use (native macos unix windows).
84\row
85 \li --objects-spacing
86 \li
87 \li Ensure spaces between objects (only works with normalize option).
88\row
89 \li --functions-spacing
90 \li
91 \li Ensure spaces between functions (only works with normalize option).
92
93\endtable
94
95\section2 Arguments
96\target arguments
97\table
98\header
99 \li Arguments:
100\row
101 \li filenames
102\endtable
103
104\section2 Details
105\e qmlformat is flexible and can be configured according to your needs.
106
107\section3 Output
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.
110
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.
114
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.
120
121\warning \c{--write-defaults} will overwrite any existing settings and comments!
122
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
126inplace.
127
128\code
129 // FileList.txt
130 main.qml
131 mycomponent.qml
132\endcode
133
134Then, use it like
135\code
136 qmlformat -F FileList.txt
137\endcode
138
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.
143
144\warning If you provide -F option, qmlformat will ignore the positional arguments.
145
146*/