Commit Graph

62 Commits

Author SHA1 Message Date
Maximilian Goldstein ad02973c05 qmllint: Move deprecation logic to qmlcompiler
Moves the remaining logic for handling deprecation warnings to qmlcompiler furthering the goal of removing checkidentifiers for good.

Change-Id: I21ac524ea9c02b2e8c8f65962011976927fd7432
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-07-28 13:38:46 +02:00
Maximilian Goldstein 2eb6d20246 qmllint: Use type propagator to provide unqualfied access warnings
Do not rely on checkidentifiers to provide unqualified access warnings anymore. Using the type propagator ought to be more accurate and will help remove the relatively hacky checkidentifiers code completely later on.

Change-Id: I40cc040b9455962abbd2ec84cdb494fcec1ab79d
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-07-27 09:43:23 +02:00
Maximilian Goldstein 3b3d0c6f3c qmllint: Implement severity levels
qmllint now supports logging levels of different severities. Still lacking a good way to toggle the verbosity more granularly though (i.e. disabling only info messages while still receiving the rest).

Change-Id: I71abddcdf1adf60315a87d776af8085acf7aeffe
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-07-02 17:25:21 +02:00
Maximilian Goldstein 3b28a298b0 qmllint: Formalize fix suggestions
They are now handled by the logger instead of being done by external classes using the ColorOutput directly.
This will allow for modernizing the logger and for automatically applying those suggested fixes.

Fixes: QTBUG-94170
Change-Id: I90b960d22cb91203b8e8a5c69b0fdaf6fca2fc0c
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-07-01 18:08:00 +02:00
Maximilian Goldstein 4063895a28 qmllint: Ignore unqualified access in custom parser components
We currently can't handle all special cases with custom parsers (i.e. signal transitions) so we need to ignore unqualified accesses except for those specific instances where we already have some special handling implemented (e.g. Connections).

Pick-to: 6.2
Task-number: QTBUG-77417
Change-Id: Iea86d4b56e56091c7acffc29a0259de412fa1624
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-22 13:14:27 +02:00
Maximilian Goldstein 3c95bf5b6d qmllint: Move a lot of warning logic to qmlcompiler
Moves the majority of qmllint warning logic to qmlcompiler, making them available to all tools using the library.
The end goal is to get rid off the additional AST visitor in qmllint altogether (We can't quite yet until we have ported over type interference).
This also prepares qmlcompiler to move to a two pass approach which isn't fully implemented in here yet due to the size of the change.

Pick-to: 6.2
Change-Id: Id2e108340d26a75085ce6ed97d56dec03ea3a12d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-06-09 12:46:02 +02:00
Maximilian Goldstein 401b515626 qmllint: Utilize qjsroot.qmltypes
Previously for some types like QString, QDateTime and QRegularExpression and others there was no sensible type information available.
Now that we have qjsroot.qmltypes we can refer to its type information in order to resolve these types.

Change-Id: Iea88cf467c694299396630e0f180ca6ff4ca3847
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-14 10:43:41 +02:00
Maximilian Goldstein 44342fb446 qmllint: Fix unknownBuiltins not being ignored in all cases
Previously we only skipped over them when they occurred in a property access chain (not covering the beginning, methods etc.) now we should always ignore them safely.

Change-Id: I405de6d97a15cba1db641b2c8310427cc9558d68
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-11 10:33:16 +02:00
Maximilian Goldstein 643b590005 qmllint: Fix newlines when disabling unqualified access warnings
Previously you'd get a bunch of newlines regardless of whether or not a warning was actually produced.

Change-Id: I9b09f68d5190f2b6112f650900ffb1429be8c788
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-30 13:07:06 +02:00
Maximilian Goldstein ddb31fe22e qmllint: Do not choke on self attaching types
Previously qmllint would land in an endless loop when going over self-attaching types.
This is now fixed and we also ensure that other cyclic type relationships can't cause the same issue.

Change-Id: I788139a9632abe48c470f5f4e2dfb0cd96699d90
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-29 14:47:44 +02:00
Maximilian Goldstein acdef32ab9 qmllint: Properly handle "on" bindings
Previously "on" bindings were handled like normal property assignments, this is obviously wrong.

Fixes: QTBUG-93189
Change-Id: Ifda51103cafeb2488c54e0ac702e564771767f18
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-28 15:59:43 +02:00
Maximilian Goldstein 2d5e4a893d qmllint: Remove unnecessary newlines
Change-Id: I4349c12dee01b2e9bfecb58a4390d297dcbfc675
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-28 13:37:39 +02:00
Maximilian Goldstein 001bec1aa2 qmllint: Store property's binding type separately
In the past the type of a property's bindings would override the base type.
This would lead to incompatible type warnings when trying to override that binding with another value that was compatible with the property type but not the binding one.

Change-Id: Ie0c0843e34f24e05aae7bbb429899fbe076e7262
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-26 14:39:42 +02:00
Maximilian Goldstein 63c906ddc8 qmllint: Warn about deprecated functions
Now qmllint will also warn when functions have a Deprecated annotation which previously only applied to properties and elements.

Task-number: QTBUG-84895
Fixes: QTBUG-79857
Change-Id: Ie1436822dc06bfd1ee4305a8468900409c3f8b0a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-19 10:15:13 +02:00
Maximilian Goldstein 7a9b84ca6d qmllint: add options for setting logging levels
Add the ability to individually disable and set the severity of all warnings produced by qmllint.

Change-Id: I46081f8b37fb90f8d0f4a5f2f08223d7b7285041
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-09 15:26:52 +02:00
Ulf Hermann d97ff367c2 qmllint: Initialize special casing for QString on checkMemberAccess()
If the very first component in the member access chain is already a
QString, we need to expect "length" as only valid property from the
beginning. Like we do for lists.

Task-number: QTBUG-92447
Change-Id: I4549f4da52cb1c0968b24813f0a921a129da28ee
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-08 23:26:19 +02:00
Ulf Hermann 4beba3a2b6 When resolving property types, also update the property type names
Otherwise we end up with a mixture of QML and C++ names.

Pick-to: 6.0 6.1
Task-number: QTBUG-92447
Change-Id: I94c44307d8dd762d11cfd8f178f33ab6a895ee83
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-07 13:40:52 +02:00
Ulf Hermann b28c8c87ec Fix string type name in qmllint
The "length" property is special cased because it's the only own
property of any JavaScript built-in type. As we've changed the internal
name of the string type in builtins.qmltypes, we need to reflect this in
qmllint.

Fixes: QTBUG-92447
Pick-to: 6.0 6.1
Change-Id: I9a5c7e9ab3da686bb6ac3fdffa36269abb0eb6ea
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-07 13:40:45 +02:00
Maximilian Goldstein 954071f372 qmlcompiler/qmllint: Use unified logger
Improves the logging situation greatly by allowing all logging messages to be assigned different severities,
highlighting the code that caused them and by now ensuring a qmllint warning will always result in a non-zero exit code.

A later patch will expose more of these options to the user.

Change-Id: Id9b036fe3ba80dd18e9f8cb1b05efa891713d5a8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-29 12:31:01 +01:00
Fabian Kosmale 603b8e09ac qmllint: Document and cleanup IssueLocationWithContext
Add a few comments to describe IssueLocationWithContext. In addition,
remove useles casts. Also remove uselessly constructing QStrings by
adding a few QStringView overloads.

Change-Id: I3c6e03f38cbe251deda66bd9257462d9ee9cd065
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-25 21:25:23 +01:00
Maximilian Goldstein eb74d99d02 qmllint: Add support for warning about unused imports
qmllint will now show an information line pointing out import statements that are not needed.
It will not warn about imports that are redundant however, since there are legitimate reasons for having these.

Fixes: QTBUG-83237
Change-Id: I9588b5fa8a8efd37b48c9b349a448e580efb1452
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-25 11:34:41 +01:00
Maximilian Goldstein b07d653c09 qmllint: Fix accessing attached types with prefixes
When ever a attached type lookup fails we have check whether combining it with the next member would make it work.

Fixes: QTBUG-83762
Change-Id: I8d159ccc07442f3939b40ea5f6b737da18439615
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-19 13:21:15 +01:00
Maximilian Goldstein bbba1e5614 qmllint: Implement deprecation warnings
Make qmllint warn about @Deprecated {} annotations.
Also adds support for annotations in qmlcompiler.

[ChangeLog][QML][qmllint] Add support for deprecation annotations.

Task-number: QTBUG-84895
Change-Id: Ia506a6c0077a2b9ab3bf4fdac207bd0540635b30
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-08 15:54:02 +01:00
Maximilian Goldstein 25ae86d1d9 qmllint: Fix unknown properties on var
Since the type of a var may change at runtime and we thus can't make any good predicitons
on its actual underlying type we will ignore it from now on (as already done for variants).

Fixes: QTBUG-84060
Pick-to: 6.1
Change-Id: I36795ef2047629d3c870bf8a9df59dcd3db06633
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-03 14:28:31 +01:00
Ulf Hermann ab71cdafca QML: Warn about variables being used before their declaration
This collides with injected signal parameters. qmlcachegen cannot tell
those cases apart.

[ChangeLog][QML][Important Behavior Changes] QML warns about JavaScript
variables being used before their declaration now. This is almost always
a mistake. It is particularly dangerous in the presence of injected
signal parameters because qmlcachegen cannot identify a name collision
between an injected signal parameter and a variable being used before
its declaration. It therefore miscompiles such code. You can turn off
the deprecation warning using the "qt.qml.compiler" logging category.

Pick-to: 6.1
Task-number: QTBUG-89943
Change-Id: I8a9424ca8c6edd562402fe5c560ba7e8344b5585
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-11 17:37:53 +01:00
Maximilian Goldstein 5fb34b67b8 qmllint: Fix segmentation fault
Pick-to: 6.0
Change-Id: Ie04ad4221b25628687c2575facf90488b83d21bf
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-03 16:32:49 +01:00
Ulf Hermann f6fc35b45b QmlCompiler: Allow for multiple extensions per object
Previously, the assumption was that each object could only have a single
extension object. As proven by the new qqmllanguage test this is not the
case. Each registered object in the type hierarchy can have its own
extension. Therefore, adjust the algorithms that generate qmltypes and
iterate the extension objects when analyzing them.

This leads us to the realization that anonymous types can in fact
meaningfully carry extensions and implement interfaces. Adapt
qmltyperegistrar accordingly.

For the test to compile, however, we need to realize that the class
declaring interfaces needs to befriend all potential subclass's
QmlInterface structs. Fix that, too. The rabbit hole went deep.

Change-Id: Ia451897e927e03b95c3062e829edf1dfcd216613
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-01 16:51:51 +01:00
Ulf Hermann ed59dfeb70 qmllint: Complain if member access check fails for namespaced types
Before, we would prepend the namespace to the name, but then continue
right away, never checking the new name.

Change-Id: If90db7d33536fb4b549321c2d6b677040605b6f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-26 13:19:38 +01:00
Ulf Hermann 39944e8467 qmllint: Remove exceptions for most unknown builtins
All those types are properly defined in the qmltypes files now. We just
need to search the enumerations the same way as methods and properties
in order to find everything.

Also, deduplicate the code that resolves properties, methods, and enums
by using a common template for iterating the scopes.

Change-Id: I0bf1423974d0ec8f602ecd0342522b3e981a8586
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-21 08:45:16 +01:00
Ulf Hermann 3ae2a6a47c qmllint: Support extended types
Fixes: QTBUG-90448
Change-Id: I5fb6b3d9223ae95ca7e039c5b9139ed086052c29
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-20 13:33:52 +01:00
Ulf Hermann d260e713bd QmlCompiler: Don't add imports with "as" to the context
That is wrong. The context does not contain such objects. Instead, mark
the names as namespaces in the imports by giving them an empty type.

Change-Id: Ie9d0bba592863878d2220cee59be369ba2534f17
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-12-05 21:48:48 +01:00
Ulf Hermann 6a605df673 QmlCompiler: Allow more convenient access to enums in QQmlJSScope
Change-Id: Ibac4dd7641a89b686bee63cf974b2257a35631a2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-12 08:06:34 +01:00
Ulf Hermann 328759cdeb QmlCompiler: Properly discern between inherited and own names
Previously, we would mix them up on importExportedNames(), which was
also misnamed. Now we keep them in their proper place in the scope
hierarchy, so that we can identify which scope a property came from.
Exceptions are the qmllint-specific treatment of parent properties and
Connections elements.

Change-Id: I7c012388b16c83439d6f2de2e83fac0da4940d30
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-22 13:11:49 +02:00
Ulf Hermann 678d4ec4b6 Unify QQmlJSImportVisitor and FindWarningsVisitor
They are both pretty much doing the same thing, except that the import
visitor is not as thorough. We need the full analysis in QtQmlCompiler,
so we successively move the code over.

Change-Id: If7fb47f88165fd8b61f4ccc408ccfbb7dad533e6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-15 10:44:25 +02:00
Ulf Hermann f98c961da6 qmllint: Defer resolution of types read from QML files
When importing a directory we most likely don't need all of the files in
the directory. Therefore we now parse them only when they are accessed.
This speeds up the execution and will allow us to process imports
recursively without running into infinite recursion.

Change-Id: I0c79313de792249e6bb86144b5014a7787dbdc5b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-15 10:44:20 +02:00
Ulf Hermann e7e0465669 qmllint: Capitalize importer warnings
Refactor the "prefixed message" mechanism into ColorOutput.

Change-Id: Ie982e641771f3367406f48a8bcfd2bd3da122b16
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-07 10:42:36 +02:00
Ulf Hermann 7200da29a8 QmlCompiler: Move ScopeType and JavaScriptIdentifier into QQmlJSScope
They don't begin with 'Q' and they are not very useful outside of
QQmlJSScope.

Change-Id: I3363ac4d29be7a9cb5c9f7f3af1727c99e886825
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 14:59:26 +02:00
Ulf Hermann 2059c8be90 QmlCompiler: Rename metatypes_p.h
Those are specific to QML/JS.

Change-Id: I45a5d4eb6c53bd5ca4026e042af83c4afaa4953c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 14:58:42 +02:00
Ulf Hermann d200ccf920 QmlCompiler: Rename ScopeTree to QQmlJSScope
That is a better name.

Change-Id: I34a6867692a236dd16ed8e3a68866f994eab02d2
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-05 14:58:36 +02:00
Ulf Hermann b2e1183cb7 qmllint: Remove member access chains from ScopeTree
What we need there is a proper type inference. This should be added
separately. For now, keep the member access chains local in qmllint and
don't pollute ScopeTree with them.

Change-Id: I9f50aa4e54b285bd93e7bd4cd17797509df0c168
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:33:23 +02:00
Ulf Hermann 65b6365ffb qmllint: Remove ScopeTree::m_unmatchedSignalHandlers
Rather, immediately output the warnings when we encounter them.

Change-Id: I4bd1a5491a47cb0232bfdd4e325f8f122593aa39
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:33:17 +02:00
Ulf Hermann 7957752447 qmllint: Unify injected and "normal" JavaScript identifiers
The specifics of how to warn about the injected identifiers are moved
out of ScopeTree as that is not related to the structure of the scopes.

Change-Id: I26418c3fa492da8339abf045a4034a8464b7bbb8
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:33:10 +02:00
Ulf Hermann 5296c163ac qmllint: Remove C++ types from the importer interface
We don't use them anymore. Now we can also make all the ScopeTrees const
again as we don't need to modify them anymore after importing.

Change-Id: I3ece767f4f62f06cb0640f1f191eb8d98400717c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:32:51 +02:00
Ulf Hermann e548c8576d qmllint: Don't use C++ names of QML types
The C++ names are an implementation detail of the importer, and qmllint
has no business messing with them. All the types are supplied as
ScopeTree by the importer now.

Change-Id: I3ef2b5da1dc19f95c7f2a5d80fa1297ba10bef8f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:32:42 +02:00
Ulf Hermann d9e98c7f6b qmllint: Remove exportedQmlNames from import results
We don't need to expose them anymore.

Change-Id: Ibb25f688459972f718f9a051fbb7265c7e5b5f92
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:32:36 +02:00
Ulf Hermann 48426aa705 Move the import handling code out of qmllint
We want to re-use this logic in other places.

Change-Id: I63cbee86a83265ddd241a4fae9ce8c48f38b5f18
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-10-02 15:32:15 +02:00
Ulf Hermann f0031c949e TypeDescriptionReader: Don't export C++ names as QML names
This is just wrong. The types are not visible in QML under their C++
names. Indeed, this way we reveal a number of places where we confuse
the names. Fix those in turn.

Furthermore, one of the tests was incorrect. The qmltypes files did not
contain an export entry for one of the types, and therefore the type was
formally anonymous in QML. However, we did access it via its C++ name.
Fix that by exporting the C++ name.

Change-Id: I8dd96334076b90fb174daf5b285d622f96495f56
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-25 23:57:59 +02:00
Ulf Hermann 8c8df9e025 qmllint: Split available names into exported, imported, C++ names
exported names are the names a component intends to export. imported
names are the names the importing component sees, possibly adding a
prefix. C++ names are only used in qmltypes files for non-composite
types.

Change-Id: I843e34f07a026a06931ed76d72a3cce98e3e5552
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-25 23:57:59 +02:00
Ulf Hermann 5458f379ac ScopeTree: Remove the "name" property
It was rarely used and only caused confusion. Use internalName instead.

Change-Id: I196b1d77db04a2cb6e3cd0447d34ce9bae0b9cd5
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-25 15:21:41 +02:00
Ulf Hermann 5a88c06665 qmllint: Clarify the meaning of the various names a scope can have
... and notice that they are misused everywhere.

Change-Id: I2254993dc5d11e967e7e83c6f0efb37fa17744be
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-09-25 15:21:41 +02:00