QML Format
-
Why does the QML formatter insist on putting empty newlines at the start of all my files? For example, most of our files look something like this. Running the QML formatter at QtCreator -> "Tools" -> "QML/JS" -> "Reformat file" puts 1-2 blank newlines before the header. Why? I tried running the formatter on several of Qt's example files with The Qt Company's header and it does it to them too. Is there any way I can write my comment headers so it doesn't do this and just starts on line 1? Its incredibly annoying.
/**************************************************************** * file.qml * Description of file ***************************************************************** * Several lines of copyright notice and boilerplate company info * blah blah blah * blah blah blah * (c) 2020-2022 ****************************************************************/ import QtQuick 2.12 ...
I have several other beefs with the QML formatter (My only configurable options are indent size and tabs vs spaces? Really??) but I found a few other forum posts complaining about the same thing to no avail so I won't go into that here.
-
Hi Stewy,
which version of qml format are you using? I have observed inconsistencies regarding both the behaviour with new lines (or removing blank lines) and handling comments between qmlformat in Qt 5 and 6. I also noticed this with respect to the header comment and the reordering of some of the import statements to before the header comment in qmlformat with Qt 5.
Do you also have some more concrete examples or minimal examples of wrong behaviour? Have you looked into the behaviour in more detail? The next step is a bug report or support request.
TLDR: Which qmlformat version? Tell me some specifics, then we can go ahead and report.
-
Here are some bug reports for qmlformat
- https://bugreports.qt.io/browse/QTBUG-105478
- https://bugreports.qt.io/browse/QTBUG-105479
- https://bugreports.qt.io/browse/QTBUG-105480
Can you add some observations?
-
This is in regards to Qt5. As far as I can tell, this behavior is present on 5.12 and 5.15.
As far as concrete examples and mimal examples, the snippet I provided above should suffice. Literally copy/paste that at the top of any QML file, and reformat and the extra lines will be added.
Thank you for linking those bug reports. They are all related to Qt6 and report as fixed. Seems like qmlformat was just improved considerably in Qt6. Guess I'm just out of luck for Qt5. Perhaps I'll do as they say and try building a static Qt6 formatter from source and using that on Qt5...