KDAB contributions to Qt 5.4: qmllint
One type of bug I see very often comes down to syntax errors in QML and JavaScript files. Most of the time these errors are simple typos; however, they creep in, go unnoticed by continuous integration and sometimes reach production — especially on delayed loaded components.
I like fixing bugs, but what I love even more is not fixing them, so I wrote a command line tool that can easily be integrated into our CI system so we can nip them in the bud at build time.
Enter qmllint: a command line QML syntax checker. Example usage:
$ qmllint ClickableImage.qml ClickableImage.qml:17 : Expected token `numeric literal'
Verifying all files:
$ find -type f -name \*qml -exec qmllint \{\} + ./qml/SettingsPage.qml:35: Unexpected token `if' ./qml/AboutPage.qml:35: Expected a qualified name id
qmllint comes with Qt 5.4 and lives alongside other Qt tools.
Furthermore, I would also recommend using other linter tools in your project, such as json_verify or xmllint. Do not do manually what could be automated by the build system!
Caveats
qmllint cannot catch semantic errors. There are cases where QML files are syntactically correct but have other types of problems:
Bar.qml:1 TypeFoo is not a type Bar.qml:2 module "QtQuickControls" is not installed Bar.qml:6:9: QML Rectangle: Cannot anchor to an item that isn't a parent or sibling.
There are no plans on my part to make this tool smarter, I like the “do one thing and do it well” philosophy, so it is finished. Checking for these kinds of mistakes is also very difficult, f.i. because we would need to depend on the QML context of a running application.
But don’t worry, my next blog post will address automating semantic validation, so stay tuned!
Excellent idea! Will give it a try with Qt 5.4.
Will that also get into qt creator? I personally prefer command line but it would be also nice to run this at the build step in qt creator.
Really handy tool, thanks for sharing!
Petar, I guess you can already use it with your projects with a QMAKE_EXTRA_TARGETS pre step which would then also be performed within Qt Creator builds?
QMAKE_POST_LINK is also useful