Commit Graph

96 Commits

Author SHA1 Message Date
Maximilian Goldstein 56c16d0e97 qmllint: Exclude children of custom parser elements from warnings
Some warnings caused by the children of custom parser elements also need to be ignored.

Change-Id: Iff3c6e5ce2ea334c6de7a14c8592ee1ebf80bb58
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-05-03 08:40:50 +02:00
Maximilian Goldstein 5f0e3d4ea7 qmllint: Handle UiArrayBindings properly
This doesn't actually properly process them yet but at least it's a step in the right direction and makes sure array elements aren't just added to the parent scope.

Task-number: QTBUG-93358
Change-Id: I3d400abd10df032ee16c9c1dfc13562d36c22169
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-30 12:03:51 +02:00
Maximilian Goldstein 5cfce9f41c qmllint: Fix multiple attached property bugs
Fixes that inherited attached properties are not found.
Also fixes that unresolved attached properties were not detected as such by isResolved().

Fixes: QTBUG-93231
Change-Id: I8917721f1e578af22997d676457fe52b21041c51
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-29 17:55:36 +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 68982dbd0a qmllint: Fix typename conflicts
Fixes blindly overwriting conflicting typenames, instead pick whichever type provides the newest version.

Fixes: QTBUG-93241
Change-Id: Icc238cef94b33cbc7653641f7fe2feac0d219789
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-29 12:04:34 +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 4c8fc3ecf1 qmllint: Fix false positive warnings for non-list default property
We stored whether something was assigned a default property in the scope the property stems from rather than the one where it occurs.
This leads to issues when two destinct elements both share the same base type and want to assign a default property.

Task-number: QTBUG-93189
Change-Id: I0560a0ffc6f83849333f8f5fad8e760bd05bec9a
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-28 09:57:55 +02:00
Maximilian Goldstein 077b8f8df4 qmltypes: Add information about QQmlCustomParser
Adds a macro called QML_CUSTOMPARSER which will result in a hasCustomParser flag to be set in qmltypes.
Also ensures qmllint does not warn about unknown properties when a class utilizes custom parsers.

Fixes: QTBUG-93027
Change-Id: I7559d79c9bf06a0a7a93f54370948f12d09dd64e
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-27 09:35:47 +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 09c8684a95 qmllint: Fix several type checking issues
- Fixes the issue of QQmlComponent properties showing a type mismatch that isn't there
- Fixes duplicate scopes with the same internal name not being recognized as type matches
- Does not warn about incomplete / unresolvable types being incompatible anymore

Task-number: QTBUG-92571
Change-Id: Ia4399c44b87fee6614f2b8c95cb28fcaeec780b4
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-23 13:30:02 +02:00
Maximilian Goldstein c44b350bf6 qmllint: Warn about multiline strings
Task-number: QTBUG-92448
Change-Id: Ic6305f05cb8a0af5c36ac03d8b541ac78cea0612
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-20 14:36:07 +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
Fabian Kosmale 3c7949ac2d qmltyperegistrar: Do not omit change signals from qmltypes files
qmltyperegistrar used to omit change signals from qmltype files if they
had neither a version nor arguments.

This does however cause issues with the semantic analysis of signal
handlers, who in this case would not find the matching signal. Instead
of adding additional logic in qmllint and any other place which might
need that information, we now simply write out those signals, too.

Pick-to: 6.1
Fixes: QTBUG-92372
Change-Id: Iaa6137c5d45f94e4874dc285e23a24f9c8319bb6
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-16 14:29:55 +02:00
Maximilian Goldstein d506b6360c qmllint: Fix non-existent default property for Component
Before children of Component caused errors about a non-existing default property.

Task-number: QTBUG-92571
Change-Id: I702ea79cf18221c35be48a86c6da35e809de073f
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-16 14:29:55 +02:00
Andrei Golubev 02e8062461 Fix QQmlJSImportVisitor::visit(UiObjectBinding *)
Visit UiObjectBinding shouldn't create any properties, otherwise we end
up having invalid QQmlJSScope state in cases with attached properties
(and maybe somewhere else)

property QtObject prop: QtObject {...} is parsed as two AST elements:
1. As UiPublicMember, which handles a property definition
   "property QtObject prop" (and, consequently, creates the property)
2. As UiObjectBinding, which handles a property assignment
   "prop: QtObject {...}"

As a drive-by, refine the endVisit(UiObjectBinding *), which sets
the property type. Now, only update the property when property
already exists and when the new property type has the same type
hierarchy (in other words, property type must be a base of a new type).
At the moment endVisit() issues an error if either of the
preconditions is not satisfied

Test the fix through tst_qmllint

Change-Id: I149090ffe46ae86268dd2c3b0ec3713b6bde0627
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-14 17:46:06 +02:00
Evgeniy A. Dushistov 06dc505b94 add "double" into the list of built in QML types
Also this fixed "property type checking" for qmllint
in case of QML code like "property double xyz"

Fixes: QTBUG-92566
Change-Id: Ice33be4287ce0eba2cf9dfaabb760406bdca02b7
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-14 18:46:06 +03:00
Maximilian Goldstein 1c0e771197 qmllint: Fix QQmlComponent default property incompatible type warnings
Assigning any element to a QQmlComponent property implictly wraps it into a Component.
Thus checking for compatible types does not make sense here.

Fixes: QTBUG-92571
Change-Id: Id72f69d30d8506193c52a51b038b9c218ac85917
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-04-14 14:10:07 +02:00
Andrei Golubev 5374dc4299 QQmlJSImportVisitor: add find-or-create version of enterEnvironment
It seems that in cases of grouped and attached properties we don't want
to create a new scope every time, but instead reuse the created one,
falling back to create if the scope doesn't exist

Consider:

```qml
QtObject {
  myGroup.property1: 42          // case 1
  myGroup.property2: "hello"     // case 2

  MyAttached.property1: 42       // case 3
  MyAttached.property2: "hello"  // case 4
}
```

The intuition tells that cases 1 and 2 should use the same shared
scope "myGroup" and so should cases 3 and 4 both use the same "MyAttached".
Creating a new scope each time for attached and grouped properties seems
erroneous

As a drive-by, add attached property type to tst_qmllint and test
that this still works after the changes to the related code

Change-Id: Ib1ae85b404a7954a3a3211cbd267c414b98ac59d
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-13 19:19:56 +02:00
Evgeniy A. Dushistov 8ac9a3f80d Check also property type names
At the moment, qmllint only check the types of objects and classes
being imported, it totally ignored types of properties that should be
also imported.

Fixes: QTBUG-92449
Change-Id: Ia5173bed84640d93fc48f6239179604ceb5db2cd
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-04-13 11:43:45 +03: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 2e85f3492b qmllint: Warn about bindings on deprecated properties
qmllint will now warn about bindings on deprecated properties as opposed to only warning when the property itself referenced.

Fixes: QTBUG-92207
Change-Id: I93c54d55e2ab2ca0648f67ac967c792d3ba60844
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-30 08:47:35 +02:00
Ulf Hermann 213adb6692 Properly mark composite singletons in QQmlJSImporter
Change-Id: I9063765b37528489a8e350fe63b2babdd038fe1a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-25 21:25:30 +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 6ddb78735b qmllint: Warn about failing imports
Warn when an import fails instead of silently ignoring them.
Without these it was impossible to tell whether a type was not resolved due to an unresolvable import or due to other reasons.

It also fixes the previous behavior of just dumping the types of qmltypes into the rootScope if manually imported.
Now they are only are present when actually importing one of the modules mentioned in the type's export statement.

Change-Id: I62bdd99828702ed02512eaac30f7f99b98d1df28
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-19 14:57:17 +01:00
Ulf Hermann e228615c84 qmllint: Resolve field member expressions on aliases
Change-Id: I8332abda8983bae47110573d765d5733ff4589e6
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-12 17:15:29 +01:00
Andrei Golubev 6f514e88fe Don't duplicate imports for different versions
We only discern imports if they live in different directories. Versions
are not handled, yet. If we add support for versions, the versioning
should be applied on processImport().

Done-with: Ulf Hermann <ulf.hermann@qt.io>
Change-Id: I2243452457e76a91042d1556edc5d36826560758
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-03-09 16:46:57 +01:00
Andrei Golubev 602982993c qmllint: check default properties
Implement the check for default properties

Default aliases are not included in this patch

[ChangeLog][QML][qmllint] Add support for default properties

Change-Id: I2d0330e32c1f49c83d3a4ed602250b6bfd4ec674
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2021-03-09 10:13:34 +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 7f3692f5ce qmlcompiler: Add support for required properties
Change-Id: I2687de04120ab224c5ccc409930526c29d8915bb
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2021-03-03 16:40:05 +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 7ecd4b6d1f qmllint: Resolve imported files by qrc path if available
If a file is part of the resource file system, the implicit directory is
also in the resource file system. We can use QQmlJSResourceFileMapper to
figure this out.

Change-Id: I48d86c308c7ec38d9971b84e7f059daa3baf63ee
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-24 13:01:48 +01:00
Ulf Hermann 1a4b0929de QtQuick.Shapes: Declare dependency on QtQuick
Otherwise qmllint and other tools won't know what QQuickItem is in this
context.

Pick-to: 6.1
Change-Id: I68da08cf2c41f17a2623f30303ac8f66b7b9329a
Reviewed-by: Maximilian Goldstein <max.goldstein@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-22 10:58:45 +01:00
Ulf Hermann 75b99a10b3 qmllint: Support enum types from other scopes
In qmltypes, enum types can be scoped, just like in C++. Resolve those
scopes.

Also, resolve the enum scopes only once, in order not to duplicate the
types.

Pick-to: 6.1
Change-Id: I095ec11f0ffec8e0e5f1034023c8956d2d39f660
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-22 09:44:33 +01:00
Ulf Hermann 08c8e8ac3b qmllint: Check for existence of property types
For each binding there should be a property and that property should
have a type we recognize.

Enums can be property types in C++. We support this by adding child
scopes for such enums. The child scopes are then referenced by the
QQmlJSMetaEnums and derive from int.

The test then reveals that we were missing a few properties in
QtQuick.tooling. Add those.

Pick-to: 6.1
Change-Id: I1deef94393ee0e17d34c2dc5980ebfbf25417f36
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-20 08:43:32 +01:00
Ulf Hermann f34ecc8f99 qmllint: Resolve attached property scopes
Previously, all attached property scopes were just ignored.

Pick-to: 6.1
Task-number: QTBUG-84369
Change-Id: I324becf92402eacea9d150e6e51359edae562dde
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-19 08:33:17 +01:00
Ulf Hermann fe7318a6cf Layouts: Depend on QtQuick
If we don't declare the dependency our tools won't figure out where
QQuickItem comes from when analyzing the dependency hierarchy of
layouts.

Pick-to: 6.1
Change-Id: I389c9e513a3a65143aa6b6fbf508eee584970181
Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-19 08:33:11 +01:00
Ulf Hermann 67c8afff34 qmllint: Don't create properties for "on" assignments
"on" assignments are assignments to the default property, with the
property given interpreted as the target for the inner object.

Pick-to: 6.1
Change-Id: Ia93a171f759964d2c00d6c0293a5434f588123af
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-16 13:15:19 +01:00
Maximilian Goldstein 4660f51f25 qmllint: Fix false unknown grouped property warning
We seem to be checking grouped properties twice by endVisit(UiObjectBinding*) and endVisit(UiObjectDefinition*).
So the UiObjectBinding variant is removed here as this gets run before all type information is available.

Change-Id: Idfe23869792f787df6109cde3b6bc1d96cce3dc3
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-12 11:57:11 +01:00
Ulf Hermann f0ecad1e99 qmllint: Warn about too many or mismatched signal parameters
It's easy to mess this up when you transform your signal handlers into
functions.

Task-number: QTBUG-89943
Pick-to: 6.1
Change-Id: If35be2f6828a0e19aada19abb41d8135b0c6ab45
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-02-11 16:38:06 +00: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 c87b4abdc0 QmlCompiler: Return after importing a script
If we don't return there, the newly imported script is promptly
overwritten by an invalid module.

Change-Id: I788a7275e2c190a20c176da35f5c76ac9f6ad02b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-26 13:53:41 +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 74060990bc QQmlJSTypeReader: Guard against empty JS files
Change-Id: Ie52ce15b7fa960ce84a6d17a21a0e307a38c726e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-26 13:19:24 +01:00
Ulf Hermann 9b407b68d1 qmllint: Fix auto-importing of qmltypes from same directory
Fixes: QTBUG-90513
Pick-to: 6.0
Change-Id: Ic39e72d6df20be30c61123a7f8091d70dbc2d924
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2021-01-21 14:17:59 +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 89636733ba qmllint: Don't crash when importing ES modules
Change-Id: Ica93a3e3fb0eb99be1498f1fcb94b09c113272d7
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2020-11-20 20:41:13 +01:00