Bug 401015 - Check that the name of the types exported to QML with qmlRegisterType starts uppercase
Summary: Check that the name of the types exported to QML with qmlRegisterType starts ...
Status: RESOLVED FIXED
Alias: None
Product: clazy
Classification: Developer tools
Component: general (show other bugs)
Version: unspecified
Platform: unspecified All
: NOR wishlist
Target Milestone: ---
Assignee: Sergio Martins
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2018-11-13 19:43 UTC by martonmiklos
Modified: 2018-11-18 20:02 UTC (History)
1 user (show)

See Also:
Latest Commit:
Version Fixed In:
Sentry Crash Report:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description martonmiklos 2018-11-13 19:43:39 UTC
SUMMARY

The name of the types exported to QML shall start with upper case letter, see: http://doc.qt.io/
qt-5/qtqml-typesystem-objecttypes.html
"... the type name must begin with an uppercase letter in order to be declared as a QML object type in a QML file." It would be useful if the clazy would catch these errors and optionally would offer a quickfix. I have wasted 3 evenings on debugging such an issue and I was not the only one who faced similar issue.


STEPS TO REPRODUCE
1. Create a QML plugin with the QtCreator's Qt Quick 2 Extension project wizard and select a lower case Class name
2. Ensure that the generated qmlRegisterType<asdasd>(uri, 1, 0, "asdasd"); exports with lower case 
3. Run clazy

OBSERVED RESULT
clazy did not reports any error

EXPECTED RESULT
clazy should report error

SOFTWARE/OS VERSIONS
Windows: all
MacOS:  all
Linux/KDE Plasma:  all
(available in About System)
KDE Plasma Version: n/a
KDE Frameworks Version: n/a
Qt Version: n/a

ADDITIONAL INFORMATION
Fix for the QtCreator's wizard is on it's way: https://codereview.qt-project.org/#/c/245440/
With some guidance I can came up with a patch to clazy as well.
Comment 1 Sergio Martins 2018-11-13 20:33:53 UTC
good idea
Comment 2 Sergio Martins 2018-11-18 17:23:59 UTC
Thinking this should be implemented in Qt instead, with a static-assert
Comment 3 Sergio Martins 2018-11-18 20:02:53 UTC
Git commit 90ef5de73c8cb09eda1480a4930450e243abe6de by Sergio Martins.
Committed on 18/11/2018 at 19:58.
Pushed by smartins into branch 'master'.

New check: lowercase-qml-type-name

Warns when QML types registered with qmlRegisterType() or qmlRegisterUncreatableType()
don't start with uppercase. It's required by the engine.

M  +1    -0    Changelog
M  +1    -0    CheckSources.cmake
M  +1    -0    README.md
M  +6    -1    checks.json
A  +4    -0    docs/checks/README-lowercase-qml-type-name.md
M  +1    -0    readmes.cmake
M  +2    -0    src/Checks.h
A  +69   -0    src/checks/level0/lowercase-qml-type-name.cpp     [License: LGPL (v2+)]
A  +38   -0    src/checks/level0/lowercase-qml-type-name.h     [License: LGPL (v2+)]
A  +7    -0    tests/lowercase-qml-type-name/config.json
A  +11   -0    tests/lowercase-qml-type-name/main.cpp     [License: UNKNOWN]  *
A  +1    -0    tests/lowercase-qml-type-name/main.cpp.expected

The files marked with a * at the end have a non valid license. Please read: https://community.kde.org/Policies/Licensing_Policy and use the headers which are listed at that page.


https://commits.kde.org/clazy/90ef5de73c8cb09eda1480a4930450e243abe6de