qmlfmt - command line application that formats QML files
Requires
- CMake 3.0 or later
- Qt 5.2 or later.
- Tested with Visual Studio 2017 and mingw 4.9.1.
- Tested with Ubuntu Bionic (18.04) and gcc 7.3.0
- Optionally QtCreator source code.
- If not present, it will be downloaded as part of the build.
Install build dependencies:
sudo apt install cmake qtbase5-dev qtdeclarative5-devBuild and install qmlfmt
cd <source dir>
cmake .
make
sudo make installUsage: qmlfmt [options] path
Without an explicit path, it processes the standard input. Given a file, it operates on that file; given a directory, it operates on all qml files in that directory, recursively. (Files starting with a period are ignored.) By default, qmlfmt prints the reformatted sources to standard output.
-?, -h, --help Displays this help.
-v, --version Displays version information.
-d Do not print reformatted sources to standard output. If a
file's formatting is different than qmlfmt's, print diffs to
standard output.
-e Print all errors.
-l Do not print reformatted sources to standard output. If a
file's formatting is different from qmlfmt's, print its name
to standard output.
-w Do not print reformatted sources to standard output. If a
file's formatting is different from qmlfmt's, overwrite it
with qmlfmt's version.
-i <indentSize> Indentation size.
-t <tabSize> Tab size.
path file or directory to process. If not set, qmlfmt will process
the standard input.
Use pre-commit. Once you have it
installed, add this to the
.pre-commit-config.yaml in your repository
(be sure to update rev to point to a real git tag/revision!)::
repos:
- repo: https://github.com/machinekoder/qmlfmt
rev: '' # Update me!
hooks:
- id: qmlfmt
args: [-i 2, -t 2]Then run pre-commit install and you're ready to go.