Commit Graph

20 Commits

Author SHA1 Message Date
Fabian Kosmale ebec92cc5c QQmlSA: mark module as TP
Pick-to: 6.6
Change-Id: I22ed887ff1ee146f1cf14f75cb986658f9dad079
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-07-03 17:29:21 +02:00
Ulf Hermann 55404fd176 qqmlsa: Fix warning about empty names
Registering "wildcard" passes is fine. We do so ourselves with the
attached property re-use pass. We don't want to trigger the warning on
every occurrence of QtQuick.Controls. If only one of the names is set,
the pass manager will indeed produce junk.

Pick-to: 6.6
Change-Id: Ib8ad749e88f7dc83fa57341bc5b192a011bddf6a
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
2023-06-20 11:38:41 +02:00
Topi Reinio 427d47b7ac Doc: QtQmlCompiler: Fix documentation warnings
* Mark functions of QColorOutput \internal to avoid QDoc warnings as
  the (private) class is not included in the module's master header.

* Fix undocumented parameters and typos.

Change-Id: Iaf744372fd573d481fb8dd744bf44709b7ae8878
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2023-06-02 16:31:26 +00:00
Olivier De Cannière 450fa684f7 QQmlSA: Change API for accessing attached types
An Element no longer exposes its attached type directly. Instead, the
function resolveAttached() was added as an analog to resolveType().

Also, added a test documenting the current attached type resolution
behavior.

Change-Id: Ib8d6713790f9ce2e2fe36b8620bbbbe36cb23705
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-06-01 09:03:29 +02:00
Olivier De Cannière 7f86e0d57c QQmlSA: Mark move SMF noexcept and specify alignment for fast-PIMPLs
Change-Id: Ia3dc17a31856047b9fd7c5da89320c7234847a59
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-31 12:08:03 +02:00
Olivier De Cannière cdd7fe05f6 QQmlSA: Create an abstraction layer for static analysis
This patch adds abstractions for QML Elements, Bindings, Methods and
Properties. This abstraction layer avoids exposing internal details and
should be more suited for static analysis tasks. It is now possible to
write qmllint plugins without including private headers.

As a drive-by, change tst_qmllint:verifyJsRoot to open files in text
mode instead of binary. This fixes an issue where line endings cause
issues on Windows.

Fixes: QTBUG-102276
Change-Id: I6b6e53f1e0078734a18f3aa51807fbe875b375f0
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-05-30 13:42:35 +02:00
Fabian Kosmale f7648db03f QQmlSA: Remove dead code
Change-Id: Iec9f607ead6ee32cc9bb1d40c5cd9967e86c7772
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2023-04-14 16:57:38 +02:00
Ulf Hermann aa49d0f2d9 qmllint: Fix attached property re-use detection
Move the detection into the QtQuick lint plugin. It's mostly meant for
QQC, so let's auto-enable it for attached types derived from
QQuickAttachedPropertyPropagator.

To this end, two new categories are introduced: The Quick lint plugin
gets its own attached-property-reuse category which is synonymous to the
default category of the same name. Furthermore, we add a
controls-attached-property-reuse category for only checking controls.
That one is implied by either of the others.

Finally, fix the id vs. scope resolution to actually do something.
This way we can give appropriate hints when the outer type has an ID
already.

Pick-to: 6.5
Fixes: QTBUG-110834
Change-Id: Ib71a9e3bbc10bac77f36db6cc441af88df20fd33
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-14 13:32:13 +01:00
Ulf Hermann 403f4117e2 qmllint: Uncruftify FixSuggestion
In this form we can expose it in QQmlSA.

Pick-to: 6.5
Task-number: QTBUG-110834
Change-Id: Ieb0cf31b6e86379c0d80f89bc6c63b129f269798
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-08 21:14:39 +01:00
Ulf Hermann 236439de7b qmllint: Add warning about PropertyChanges using custom parser
You should use the id-based generalized group form.

Pick-to: 6.5
Fixes: QTBUG-105251
Change-Id: I42edfb03059d3e8c92bfb3c311bf1ed1af7cf70e
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2023-02-03 14:31:38 +01:00
Ulf Hermann b7fd5774f6 QmlCompiler: Enforce consistency of ContextualTypes
An instance of ContextualTypes can only either hold QML types or
internal types. We always need an integer and an array type, though.

Previously, "int" was always added to the used types when it was looked
up for potentially resolving enums. This prevented the builtins from
being reported as unused import. Since we pass "int" as a separate
member now, prevent the builtins from being recorded as import location
in the first place.

Task-number: QTBUG-107171
Change-Id: I288b6e070c2039d4ac85073886c9929a2eed3998
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-11-02 09:51:14 +01:00
Sami Shalayel c52b7fdca8 qmlcompiler: refactor ContextualTypes to know its context
The code in qmlcompiler working on ContextualTypes is very confusing
as it handles internal types (c++ and synthetic jsrootgen type names)
and qml types at the same places.
Furthermore, some methods like qqmljsscope::findType() have different
behaviors when running in different contexts, e.g. in the internal
type context it needs to lookup namespaced c++ enums (e.g.
QQmlComponent::Status) while in the qml type context it needs to
lookup inline components (qmlFileName.MyInlineComponent).

Changed ContextualTypes to be a struct with the types QHash and
an enum with the context (QML or INTERNAL),

Drive-by change: amend the iterations over types.keys() to use an iterator
instead of allocating a temporary QList as types is not that small
(may contain around 400 items just for the builtins).

Fixes: QTBUG-107191
Change-Id: Ib463ec873019ea1e6844c522a090030e9a44d53f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-10-14 09:36:56 +02:00
Maximilian Goldstein a9038a6cc6 QQmlJSLogger: Switch to an ID based system
This change makes qmljslogger use an ID based system for categorizing
logging entries instead of using an enum. This allows plugins to
register their own logging categories after the fact.

It's also necessary for us to later show the warning ID when
printing warnings and for creating documentation for each ID entry.

Currently not every ID maps cleanly to only one type of warning,
this has to be cleaned up in a follow-up change.

Task-number: QTBUG-103453
Change-Id: I4cac6be7ca165b938e0ea032d077823bf17baf75
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-30 11:23:36 +02:00
Maximilian Goldstein 50ce71ae72 QmlLintQuickPlugin: Warn about unexpected property binding types
Sometimes we use var or Item property types when we actually expect
some very specific types. We warn about these at runtime, let's also
warn in the linter.

Task-number: QTBUG-102859
Change-Id: I68c2bc8b2bf5097723a432d02d76f45651f4ef12
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-06-17 21:12:47 +02:00
Lucie Gérard 0dc4fd240a Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.
Files that have to be modified by hand are modified.
License files are organized under LICENSES directory.

Pick-to: 6.4
Task-number: QTBUG-67283
Change-Id: I63563bbeb6f60f89d2c99660400dca7fab78a294
Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
2022-06-11 08:05:15 +02:00
Maximilian Goldstein 15efc5c323 qqmlsa: Make property pass check base and extension types as well
In many cases we need to also check base an extension types since
we don't always have direct inheritance
(i.e. very common with QtQuick.Controls)

Change-Id: I66307b7d0081d49611a9e61847e4363d5819bf82
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2022-06-02 10:07:40 +02:00
Maximilian Goldstein 2ebee301fd Reimplement PropertyPass to evaluate bindings
This change reimplements the PropertyPass to be based on bindings
rather than on just iterating over elements. This is a lot less
cost intensive than iterating over all properties regardless of
whether they are actually used. You may still achieve the same
thing with the more flexible element pass, just with the benefit
that you can choose what properties you want to iterate over
instead of iterating over all of them.

To demonstrate the passes usefulness the existing attached property
warnings are ported to use the binding pass and can now also warn
when an attached property is read or written in a context where
it's not supposed to be used.

Fixes: QTBUG-102860
Fixes: QTBUG-102418
Task-number: QTBUG-102859
Change-Id: Iea87a1b05b954429b8bf00fd27b60487940af679
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
2022-05-16 18:22:45 +02:00
Sona Kurazyan 2c9c1590e6 Replace uses of deprecated _qs with _s/QStringLiteral
Task-number: QTBUG-101408
Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-04-29 09:47:43 +02:00
Maximilian Goldstein fc3f4e5834 qqmlsa/PassManager: Add method for checking whether module is imported
Adds a method to the PassManager to check whether a QML document has
imported a particular QML module.

This is important as a lot of linting passes only need to run when a
certain module is present and can be skipped otherwise.

Checking for the module is accomplished by adding an invalid
$module$.<URI> scope to the imported types generated by QQmlJSImporter.
This means that not only direct imports but also indirect imports caused
by a qmldir import line will be properly detected.

Change-Id: I341f916a43c60d373d205b5571104d5c5a533d61
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
2022-04-21 21:04:01 +02:00
Maximilian Goldstein 651bf47ab3 qmlcompiler: Implement structured QML static analysis
This patch adds the qqmlsa "framework", which is meant as a starting
point for a more structured, extendible static analysis for QML.
While qmllint (or rather, the QQmlJSImportVisitor used by it) can
already do quite a few checks internally, it is hard to extend.
Moreover, the checks there are interspersed with parsing code, and might
run before all types are resolved. We also do not want to add check that
are specific to QtQuick, Controls, Quick3D... into the core QtQml
module. This poses quite a few challenges: For instance, the color in
QML resolver depends on QtQuick/QtGui to check whether a string is
actually a color.

To overcome the issues mentioned above, we introduce the concept of
analysis passes, and a PassManger class. Passes can come in two shapes
currently:
- PropertyPasses run on each property that has a binding assigned to it
- ElementPasses run on each (sub-)object instantiated in the file
  A property can have multiple bindings assigned to it (due to e.g.
  Interceptors, but also for list properties). Therefore we pass a list of
  them to the ElementPass.
  Passes which only want to handle the "normal" case of one binding per
  property can use SimpleElementPass, which for now just takes the first
  property in the list.
Passes have a pure virtual run function, in which the actual work is
done. They also have a filter function, which in the default
implementation simply returns true, which means that the pass will run.
The filter function is there to make writing passes a bit more
structured, by separating the "do I need to analyze this" question from
the actual analysis part.

To solve the issue of library dependencies, we expose a plugin interface
that then returns passes to be run based on the root component.
Then, user can create a plugin implementing the interface,
which we will load the plugins from a known location, and register all
of them. This will be implemented in the next patch in this set.

Limitations:
- The current passes cannot touch the IR, and thus cannot
  really analyze what happens in script binding.
- (inline) components are currently badly handled
- QQmlJSScope has various issuse with grouped properties

Fixes: QTBUG-101604
Original-patch-by: Fabian Kosmale <fabian.kosmale@qt.io>
Change-Id: Ic96259a947fbb17f79aa58ca613c8d0905a9a74c
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2022-03-29 13:28:04 +01:00