aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmlsa.cpp
Commit message (Collapse)AuthorAgeFilesLines
...
* qmllint: Fix attached property re-use detectionUlf Hermann2023-02-141-2/+22
| | | | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* qmllint: Uncruftify FixSuggestionUlf Hermann2023-02-081-2/+9
| | | | | | | | | In this form we can expose it in QQmlSA. Pick-to: 6.5 Task-number: QTBUG-110834 Change-Id: Ieb0cf31b6e86379c0d80f89bc6c63b129f269798 Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Add warning about PropertyChanges using custom parserUlf Hermann2023-02-031-0/+10
| | | | | | | | | You should use the id-based generalized group form. Pick-to: 6.5 Fixes: QTBUG-105251 Change-Id: I42edfb03059d3e8c92bfb3c311bf1ed1af7cf70e Reviewed-by: Fabian Kosmale <[email protected]>
* QmlCompiler: Enforce consistency of ContextualTypesUlf Hermann2022-11-021-3/+3
| | | | | | | | | | | | | | | 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 <[email protected]>
* qmlcompiler: refactor ContextualTypes to know its contextSami Shalayel2022-10-141-3/+3
| | | | | | | | | | | | | | | | | | | | | | 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 <[email protected]>
* QQmlJSLogger: Switch to an ID based systemMaximilian Goldstein2022-06-301-8/+10
| | | | | | | | | | | | | | | | 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 <[email protected]>
* QmlLintQuickPlugin: Warn about unexpected property binding typesMaximilian Goldstein2022-06-171-0/+5
| | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* Use SPDX license identifiersLucie Gérard2022-06-111-27/+2
| | | | | | | | | | | | 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 <[email protected]>
* qqmlsa: Make property pass check base and extension types as wellMaximilian Goldstein2022-06-021-16/+36
| | | | | | | | | | 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 <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* Reimplement PropertyPass to evaluate bindingsMaximilian Goldstein2022-05-161-34/+198
| | | | | | | | | | | | | | | | | | | | | | 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 <[email protected]> Reviewed-by: Qt CI Bot <[email protected]>
* Replace uses of deprecated _qs with _s/QStringLiteralSona Kurazyan2022-04-291-2/+4
| | | | | | Task-number: QTBUG-101408 Change-Id: Ic925751b73f52d8fa5add5cacc52d6dd6ea2dc27 Reviewed-by: Ulf Hermann <[email protected]>
* qqmlsa/PassManager: Add method for checking whether module is importedMaximilian Goldstein2022-04-211-0/+5
| | | | | | | | | | | | | | | | 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 <[email protected]>
* qmlcompiler: Implement structured QML static analysisMaximilian Goldstein2022-03-291-0/+155
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 <[email protected]> Change-Id: Ic96259a947fbb17f79aa58ca613c8d0905a9a74c Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Qt CI Bot <[email protected]> Reviewed-by: Andrei Golubev <[email protected]> Reviewed-by: Ulf Hermann <[email protected]>