qmlformat is a tool that automatically formats QML files in accordance with the QML 编码约定 . 更多...
用法: |
---|
qmlformat [ options ] arguments |
The following options are available:
选项 | 默认值 | 描述 |
---|---|---|
-h, –help | 显示命令行选项的帮助。 | |
–help-all | Displays help, including generic Qt options. | |
-v, –version | 显示版本信息。 | |
-V, –verbose | Verbose mode. Outputs more detailed information. | |
–write-defaults | Writes defaults settings to .qmlformat.ini and exits (Warning: This will overwrite any existing settings and comments!) | |
–ignore-settings | Ignores all settings files and only takes command line options into consideration | |
-i, –inplace | Edit file in-place instead of outputting to stdout. | |
-f, –force | Continue even if an error has occurred. | |
-t, –tabs | Use tabs instead of spaces. | |
-w, –indent-width <width> | 4 | How many spaces are used when indenting. |
-n, –normalize | Reorders the attributes of the objects according to the QML Coding Guidelines. | |
-F, –files <file> | Format all files listed in file, in-place | |
-l, –newline <newline> | Override the new line format to use (native macos unix windows). | |
–objects-spacing | Ensure spaces between objects (only works with normalize option). | |
–functions-spacing | Ensure spaces between functions (only works with normalize option). |
Arguments: |
---|
filenames |
qmlformat is flexible and can be configured according to your needs.
qmlformat writes the formatted version of the file to stdout. If you wish to have your file updated in-place specify the
-i
标志。
采用
-n
or
--normalize
flag,
qmlformat
groups all properties, functions, and signals together, instead of retaining the order you specified.
You can configure
qmlformat
by including a settings file
.qmlformat.ini
in your project source or in the parent directories of your project source folder. A default settings file can be obtained by passing the
--write-defaults
flag. This generates the
.qmlformat.ini
file in the current working directory.
警告:
--write-defaults
will overwrite any existing settings and comments!
While you can pass a list of files to be formatted as arguments, qmlformat provides
-F
option to format a set of files stored in a file. In this case, formatting will happen inplace.
// FileList.txt main.qml mycomponent.qml
Then, use it like
qmlformat -F FileList.txt
注意:
If the file contains an invalid entry, for example, a file path that doesn't exist or a valid file path but the content is an invalid qml document, then
qmlformat
will error out for that particular entry. It will still format the valid file entries in place.
警告: If you provide -F option, qmlformat will ignore the positional arguments.