aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljsimportvisitor.cpp
Commit message (Collapse)AuthorAgeFilesLines
* qmlls: find C++ & QML definitions of enumSami Shalayel3 days1-0/+1
| | | | | | | | | | | | | Implement go to definition for enums (values and keys) defined from C++ or QML. This allows user to jump to their own C++ files, and does not jump to headers outside the project folder, like private/qquickitem_p.h for example, as it might get confusing for the user to open a file in the editor that they are not supposed to edit. Task-number: QTBUG-128393 Change-Id: I0410ecf4cf810e6c6072038bffc4564eb787c7fc Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: fix '.,' in qmllint outputKai Köhne2025-07-291-3/+3
| | | | | | | | | | | wasNotFound is defined as "was not found.". Let's just duplicate the string. Also remove double space due to signalName() replacement. Pick-to: 6.10 Change-Id: Ieec4d4c02e1af16adc04b7cb0f7329a268c48c59 Reviewed-by: Semih Yavuz <[email protected]>
* qmllint: Do not warn about unknown signal handlers in custom parsersFabian Kosmale2025-07-281-0/+5
| | | | | | | | | | | | A custom parser can do arbitrary things with signal handlers inside it, even if no corresponding signal exists in itself. For instance, PropertyChanges allows to set signals on its target. Task-number: QTBUG-138173 Pick-to: 6.10 Change-Id: I8b92cb92dad8d9a53cb57b4a9ad3d2d48b24c08a Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: Give root scope the correct typeFabian Kosmale2025-07-251-0/+6
| | | | | | | | | | | | | | | | | | | | | | | | So far, resolving the id of a root element would have yielded the base type, which is problematic when you want to expose a property of the new type initially pointing to that id (as we do in some examples). Fix this by inserting a mapping from the element to m_exportedRootScope, which is the scope of the actual root type. This is similar to what we do with inline components. Some care needs to be taken, though: if the file name does not yield a valid QML type, this export should not happen. We also must be careful to do this early, before processing non-base imports, otherwise we would end up shadowing types with the same name from explicit imports (e.g. there's a Connections.qml file in the qmltc test suite using Connections from QtQuick). We also must not expose types which are lowercase; not only are those not importable according to QML semantics, but we'd also would run into issues with "var.qml" shadowing the var type. Pick-to: 6.10 Fixes: QTBUG-138515 Change-Id: Ie4a2c160cf9eda847da87816a88b17f6a5f3a8a3 Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlJSImortVisitor: Cleanup global scope setupFabian Kosmale2025-07-251-14/+19
| | | | | | | | | | | | | | | | | | | | This commit attempts to make the setup of the global scope more readable, and fixes a few (currently harmless) inconsistencies: - There's now a comment why we're creating a scope representing the global object in the constructor. - The setup happens on the actual scope representing the global scope, not on m_currentScope. m_currentScope still points to the global scope, but we prevent accidents should that ever change. - We use enterRootScope also for plain JS files (in visit(Program *)), not only for modules and QML filse. - We only call setIsRootFileComponentFlag for QML files, the concept of a root component is only well defined for QML after all. Pick-to: 6.10 Task-number: QTBUG-138515 Change-Id: I27c0a93a201a9d25609543d6ff250f701cbeb94f Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlJSImportVisitor: Avoid faulty unknown property warningFabian Kosmale2025-07-251-1/+23
| | | | | | | | | | | | | | | | | | | In QQmlJSImportVisitor::processPropertyBindingObjects, we can encounter grouped properties. So far, we used the whole compount expression to look up the property. That would of course not find any property. We now instead traverse the individual parts of the name, and look up the property chain correctly on the corresponding types. We adjust the previously added test for unknown duplicate properties to work with _really_ unknown properties (that don't exist), and instead use an adjusted version to prove that the example is completely warning free – mirroring the issue from QTBUG-138164 in a more minimal way. Task-number: QTBUG-138498 Task-number: QTBUG-138164 Pick-to: 6.10 Change-Id: I75d17c3c412159f3f6da082f54d99bdf6b3b08e4 Reviewed-by: Olivier De Cannière <[email protected]>
* qqmljsimportvisitor: give base types to attached scopesSami Shalayel2025-07-211-8/+23
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | It seems that our attached scopes have no base type: they don't inherit the attached properties or methods because their baseTypeName is not set. Therefore, set their baseTypeName, and move the resolveTypes calls inside of setScopeName() instead of potentially forgetting them after enterEnvironment/RootScope() calls. With the (resolved) base type, we know about inherited signals, like in: ``` Keys.onPressed: { /*here is the "event" argument available*/ } ``` for example where we can insert the "event" JS identifier inside the QQmlJSScope of the block of the signal handler, now that we now that "Keys" has a "pressed"-method with one argument "event" on its base type. Add a test to make sure that the body of an attached signal handler contains the JS identifier of the arguments of the attached signal to be handled. This JS identifier is used later on in qmlls to provide completions in the body of the attached signal handler. Also fix LinterVisitor::leaveEnvironment() that starts complaining about "Component" attached properties that have no child, now that attached properties have base types. Pick-to: 6.10 6.9 6.8 Fixes: QTBUG-137736 Change-Id: I8de0158ca9946d5e0e4f4f0a46614385f0edca69 Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Avoid spurious warnings when file selectors are usedFabian Kosmale2025-07-181-0/+17
| | | | | | | | | | | | | | | | When file selectors are used, we loose too much information currently, as we completely discard everything we know about the type. [ChangeLog][qmllint] qmllint and the LSP now no longer print warnings about ambiguous types if file selectors are used, and instead use the "plain" version. The QML script compiler will still conservatively reject such QML files. If warnings about such cases are desired, the new "importFileSelector" warning category can be enabled. Task-number: QTBUG-137075 Pick-to: 6.10 Change-Id: Ia87d5ab62003fe8d7d2ab9569fac2942fb1c7c14 Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: Avoid confusing duplicate property assignment warningFabian Kosmale2025-07-171-1/+11
| | | | | | | | | | | | | | | | | | | | | If we have no clue what a certain property might be, do not warn about duplicate binding assignments to it. It might be a genuine error, but it might also be: - a property of a type we couldn't resolve; that should warn about the type, but not here – it might after all be a list property if we were able to resolve the type - a binding assignment to an instance of a custom parsed type Note that the attached test case currently would still complain about the property being unknown, as it fails to correctly handle the grouped binding. That will be addressed in a follow-up commit; for now we silence that additional warning with a qmllint comment, putting the focus on the duplicate list warning. Pick-to: 6.10 Task-number: QTBUG-138164 Change-Id: Ib06a4baaef0813a45a20738cbb6efe4cf5e5952c Reviewed-by: Sami Shalayel <[email protected]>
* QQmlImportVisitor::setAllBindings: Change misleading variable nameFabian Kosmale2025-07-171-4/+4
| | | | | | | | | m_foundBindings is not, in fact, a meber variable, but function local. Adjust the name accordinglgy. Pick-to: 6.10 Change-Id: I989ea73b5304a269425fa133c7e08a6dd9d0e765 Reviewed-by: Sami Shalayel <[email protected]>
* QQmlSA/compiler: Introduce new scope typesFabian Kosmale2025-07-101-6/+11
| | | | | | | | | Instead of doing string comparisons, encode the information in the scope type for bindings and signal handler functions. Add a helper function to check whether a scope represents any kind of functions. Change-Id: I41ad1316852dd484ac54c02f99bb25e618099e62 Reviewed-by: Sami Shalayel <[email protected]>
* qmllint: Do not warn about unnotifiable properties outside bindingsFabian Kosmale2025-07-101-1/+2
| | | | | | | | | | | | | | | | | | | | | | | | It doesn't cause any harm if we are not inside a binding. There's a slight issue with the fact that we now don't warn if one extracts the read into a separate function, and calls the function inside a binding, but that is still better than spurious warnings. Fix this by checking in which context the read occurs. We currently rely on a "magic" name we give to the function's scope if it as a binding, but this will be fixed in a follow up commit introducing new scope types. We don't want to do introduce them here, as they would be new API not suitable for picking back to 6.10. Another open issue is that the onRead handler gets the outer QML scope as the context, which necessiates that we traverse its child scopes to find the actual function. Fixing that would necessiate some larger work in the QQmlTypePropagator, and is consequently deferred to another patch, too. Pick-to: 6.10 Fixes: QTBUG-138346 Change-Id: I29ea39eb32a18d9b54ded8d5e2c9a5f66051374f Reviewed-by: Ulf Hermann <[email protected]>
* Relax duplicate binding checkFabian Kosmale2025-07-091-6/+25
| | | | | | | | | | | | It is actually possible to have mutliple ValueSources on the same propery, as long as they are not all active at the same time. We can't really know whether that's the case (that can only be known at runtime), but we can employ a heuristic to avoid most spurious warnings. Pick-to: 6.10 Task-number: QTBUG-137946 Change-Id: Ie39a1368c68e1ba9aecf582df00680ae3e8c68f3 Reviewed-by: Olivier De Cannière <[email protected]>
* qqmljsscope: add line number for ComponentsSami Shalayel2025-07-071-1/+4
| | | | | | | | | | | | | | | | | | | | | | | | | Add Component line number information from MOC into QQmlJSScopes. That is needed for qmlls to find definitions of QML components defined in C++ headers. This change adds the line number information into the generated qmltypes from MOCs JSON, and reads it back into a QQmlJSScope. Instead of adding an extra member, re-use the QQmlJSSourceLocation that is inside the QQmlJSScope. Set the column to 1 for it to be valid and to simplify some code on the qmlls side. This allows to treat a sourcelocation in the same way, independently if the component described by the QQmlJSScope was defined in QML or C++. Avoid an assertion in QQmlJSImportVisitor::checkRequiredProperties() where printFix assumes that a file can be opened if its source location is valid: this change adds have valid sourcelocations to qml components defined in C++, but QQmlJSScope::filePath() can't be opened because it only contains the filename, not the file path. Task-number: QTBUG-128393 Change-Id: Idf4acc32cff60730528322286ad4ba726b502ac1 Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Catch JS variable declarations in QML elementsFabian Kosmale2025-06-271-11/+45
| | | | | | | | | | | | | | | JS variable declarations in a QML element are not allowed. The engine rejects them in the IR builder. As the linter doesn't run this part of the compilation pipeline, it would never report the issue. This commit fixes the issue by adding the necessary check. It also avoids an assert in insertJSIdentifier when assertions are enabled. Fixes: QTBUG-137030 Pick-to: 6.10 6.9 6.8 Change-Id: Iff7a6e02bf852cf3a9affcac6ec40b7bd98cda83 Reviewed-by: Ulf Hermann <[email protected]>
* Make QQmlJSScope ctor privateFabian Kosmale2025-06-161-4/+2
| | | | | | | | | | | | | | We generally want scopes to be created via the create factory function, so that they already end up in a QQmlJSScope::Ptr, as that's what we normally operate on. Adjust the few remaining use cases by adding more helper functions (cloneInto to "copy-assign"; resetForReparse to clear the existing data from a QQmlJSScope, which is done by assigning a defaulted constructed instance to it, and then repopulating some fields). Change-Id: I4eaa4a1e4e6b3f89a636571bd13e8649fc837a41 Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: Warn about using enums as type annotations in functionsOlivier De Cannière2025-06-101-0/+32
| | | | | | | | | | | | | | Until we support a proper representation of enums in the type system, all we can do is warn the user that enums can't be used as types. After the improved runtime warning added in a recent commit, this patch adds a qmllint warning to warn about the same issue but at 'compile time'. Fixes: QTBUG-135255 Pick-to: 6.10 6.9 6.8 6.5 Change-Id: I02266f21266e59eb6d4a4dbe0e4335b845c62133 Reviewed-by: Sami Shalayel <[email protected]>
* qmlcachegen: fix crash on unresolved type with required propertySami Shalayel2025-06-061-10/+11
| | | | | | | | | | | | | | | | | | qmlcachegen can't resolve all types when importing QtQuick.Controls, so scopes from QtQuick.Controls might be unresolved. Check the scope before creating a fix suggesion when checking the required properties, and add a test that tests a file with required properties on an unresolved base type "Tumbler". This also fixes the crashes from QTBUG-137196 and QTBUG-136998 it seems. Pick-to: 6.10 6.9 6.8 6.5 Fixes: QTBUG-137411 Fixes: QTBUG-137196 Fixes: QTBUG-136998 Change-Id: Ibf461b54abf84ba13bff8c4833940c7359cf2d8e Reviewed-by: Olivier De Cannière <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Suggest specific types instead of varOlivier De Cannière2025-05-301-3/+16
| | | | | | | | A test was slightly adapted as a result. Task-number: QTBUG-129307 Change-Id: I07ac61b183d9d7d237e9cf51ce3a0c6c280daa45 Reviewed-by: Sami Shalayel <[email protected]>
* TypeResolver: remove unused literal scopes data structureOlivier De Cannière2025-05-301-1/+1
| | | | | Change-Id: I76ffad9b03ea4a1b906c6e1301529baea9af7a14 Reviewed-by: Ulf Hermann <[email protected]>
* QQmlSA: extend ScriptBindingValueType for function bindingsSami Shalayel2025-05-201-6/+12
| | | | | | | | | | | | | | | | | In QtC, ErrBlocksNotSupportedInQmlUi is supposed to warn about function blocks when used in bindings. We can't detect function blocks with the QQmlSA infrastructure because we don't have access to the AST, but we still can actually detect bindings to function blocks. Extend ScriptBindingValueType to be able to recognize bindings that contain functions (JS blocks, arrow functions and lambdas). Extend the QQmlSA interface to find out if a binding contains a function so that qdslintplugin can use it in a later commit. Task-number: QTBUG-129308 Change-Id: Ic46ad6faf7a04d805084db2d9353b009e881d4dd Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Move enum warnings to linting visitor and add warning categoryOlivier De Cannière2025-05-191-27/+1
| | | | | | | | | | | | | | | | | | | | | The warnings should be part of the linting visitor. Introduce a new warning category for the exising warning about duplicate enum entries. Amends bbce9ea73fcb060916b75094f5a7fc64be5d7edd This also (re)moves the test for warnings about enums in inline components from qmltc. These warnings should be generated by qmllint. Some files that had enum inside of inline components may no longer fail to compile because of the warning. This is fine as the enum is not accessible anyways. Amends f368be4320306b637bdd5d7d8318cdb75406f2e4 Task-number: QTBUG-119890 Change-Id: I90f280e2e443504ab336b4c2ad85bf7e53e4544f Reviewed-by: Fabian Kosmale <[email protected]>
* LinterImportVisitor: move linting code from QQmlJSImportVisitorSami Shalayel2025-05-161-42/+0
| | | | | | | | | Move the stringliteral linting code into the new LinterImportVisitor class. Task-number: QTBUG-129307 Change-Id: I5f358f91c41e99383582be9fc1628814563848ed Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: Warn about duplicate inline componentsOlivier De Cannière2025-05-081-0/+11
| | | | | | | Fixes: QTBUG-126715 Task-number: QTBUG-129307 Change-Id: I739587bf6d44131d9a0bdcec4df60ab3f53e1a12 Reviewed-by: Sami Shalayel <[email protected]>
* Compiler: Replace non-ascii character from sourceOlivier De Cannière2025-05-081-1/+1
| | | | | | | | Amends db0913a323c28c93c362a9b128f62d00bb83355f Pick-to: 6.9 6.8 6.5 Change-Id: I7230644465832c9de1b8343b01948a606a15012d Reviewed-by: Sami Shalayel <[email protected]>
* qmllint: warn about duplicate property bindingsSami Shalayel2025-04-291-3/+29
| | | | | | | | | | Warn about duplicate property bindings for object and script bindings. Remove a TODO about doing this task that seemed to be at the wrong place. Fixes: QTBUG-118102 Change-Id: I46696b696f6c7e0c83e36077998d6118b14498ad Reviewed-by: Olivier De Cannière <[email protected]>
* QQmlJSImportVisitor: const-ref-ifyOlivier De Cannière2025-04-251-7/+6
| | | | | Change-Id: Ia71e88dbd983303c15e532b812550214426d4d6d Reviewed-by: Sami Shalayel <[email protected]>
* qmllint: Fix required property warning with owner mixupOlivier De Cannière2025-04-251-2/+5
| | | | | | | | | | | | | | | | Because we only search for the name of the property in the scopesToSearch and not which property that name actually references, we confuse a property of the same name in a neighboring scope for the actual required one. Include the property's owning scope when searching through the scopes. Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Fixes: QTBUG-136058 Pick-to: 6.9 6.8 Change-Id: I998901fd0840270dd2048e7257d6eaca556b513d Reviewed-by: Sami Shalayel <[email protected]>
* qmllint: Fix name of inline component scopes for required propertiesOlivier De Cannière2025-04-251-9/+9
| | | | | | | | | Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Task-number: QTBUG-136058 Pick-to: 6.9 6.8 Change-Id: Ibf412089427e4d9d5a568ee24c224b9fa41fd20a Reviewed-by: Sami Shalayel <[email protected]>
* Compiler: Move QQmlJSScope::descendants next to its only userOlivier De Cannière2025-04-251-3/+22
| | | | | | | | | | Move it next to QQmlJSImportVisitor::checkRequiredProperties and also make it filter out any scope that isn't of type QMLScope. Task-number: QTBUG-135244 Pick-to: 6.9 Change-Id: Ibf3fa90ab7db9fcd9811509b5f893aeab4f14925 Reviewed-by: Sami Shalayel <[email protected]>
* Compiler: Optimize checking required propertiesOlivier De Cannière2025-04-251-2/+4
| | | | | | | | | | | | | | | | | Checking required properties had become quite slow, especially on huge files, after daf57e29de918b7b4be7bb0d469db0c51d41bb07. Immediatelly checking for the presence of a property binding speeds things up a lot. fluentwinui3/Slider.qml, which reference a 20k line file, now compiles almost instantly again instead of talking several tens of seconds. Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Fixes: QTBUG-135244 Pick-to: 6.9 6.8 6.5 Change-Id: I4391db27f391b179ad03dabadc910f23fa932037 Reviewed-by: Fabian Kosmale <[email protected]>
* ImportVisitor: Fix nonsensical code for checking required propertiesOlivier De Cannière2025-04-251-1/+3
| | | | | | | | | | | We create and increment an iterator and then don't use it... Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Task-number: QTBUG-135244 Pick-to: 6.9 6.8 6.5 Change-Id: Ia92df8e7dc337786eba43980364ad03c747ec11b Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: don't warn about required properties in inline componentsSami Shalayel2025-04-251-0/+4
| | | | | | | | | | | | Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 that recurses into inline components when checking for required properties that were not set. We should only check inline components that are base types of the scope, and ignore all inline components in children of the scope. Fixes: QTBUG-136008 Pick-to: 6.8 6.9 Change-Id: I8c687ce97b3f2eac699e2fd535193197b5239ada Reviewed-by: Olivier De Cannière <[email protected]>
* qmlls: make QQmlJSImportVisitor process updates to filesSami Shalayel2025-04-231-0/+10
| | | | | | | | | | | | | | | | | | | Qmlls makes QQmlJSImportVisitor re-create a QQmlJSScope when a file gets updated. It turns out that QQmlJSImportVisitor only works correctly when used on an empty scopes, methods like rootScopeIsValid() don't work correctly if the scope is not empty. Therefore, reset the scopes before making QQmlJSImportVisitor run on them. Make sure that the internalName and the moduleName are still set. This fixes a bug where qmlls can't autocomplete an "in-memory" enum because the import visitor does not set the new enum values in the root element correctly on an non-empty scope. Pick-to: 6.8 6.9 Fixes: QTCREATORBUG-32634 Change-Id: If6d620f350215074f87b53bb153363f2dec06145 Reviewed-by: Fabian Kosmale <[email protected]>
* qmltc: Cleanly reject custom parsed propertiesUlf Hermann2025-04-151-6/+11
| | | | | | | | | | | | Process all properties of custom parsed types and generate errors if the custom parsed properties are actually used. Then print an extra error stating that qmltc does not support custom parsers. Pick-to: 6.9 6.8 Fixes: QTBUG-134206 Change-Id: I37e4f3f8d0ee4e0926c0d64c99a4a521b093a1ab Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* Port away from QPairZhao Yuhang2025-04-121-7/+7
| | | | | | | | QPair is just an alias of std::pair anyway. Task-number: QTBUG-115841 Change-Id: I26fc90adcc775aac9955ad57304af914dc4ed48f Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: implement WarnAlreadyX warningsSami Shalayel2025-04-101-2/+15
| | | | | | | | | | | | | | | | | Add a test for WarnAlreadyFormalParameter that was already implemented by c4d503be574b56426573e706b70149eb57e52d61. Amends c4d503be574b56426573e706b70149eb57e52d61 to also implement WarnAlreadyFunction and WarnAlreadyVar which warns about redeclaring variables with functions (and vice-versa) in the same JS scope, which is rejected by the JS runtime. Also fix the sourcelocation used for functions in JS scopes to be the identifier location instead of the function keyword. Task-number: QTBUG-127107 Change-Id: I2f541b8046524ffc642824b1500323d225daed86 Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: Do not warn about required properties in grouped property scopesFabian Kosmale2025-04-011-1/+2
| | | | | | | | | | | | | | | | | | | | If a type with required properties is accessed via a grouped scope, we can't know whether the object already exists, or whether it would need to be created. Avoid false positives and don't emit a warning when we encounter a grouped property scope, or any non-QML scope. Non-grouped, non-QML scopes should not trigger the issue, but don't need to be checked either, avoiding some needless work. As a drive-by change, don't put spaces into a data test tag (which does not play nice with running the test separately). Amends daf57e29de918b7b4be7bb0d469db0c51d41bb07 Pick-to: 6.8 6.9 6.5 Fixes: QTBUG-134887 Change-Id: I747239c5d72993cf9a1563c875cefaf89c8e52a2 Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: implement ErrInvalidIdSami Shalayel2025-03-311-0/+6
| | | | | | | | Complain about ids in qmllint that start with an upper case letter. Task-number: QTBUG-129307 Change-Id: I4cee3201d369692ead60cfcdebacf587b6d73491 Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: implement WarnAssignmentInConditionSami Shalayel2025-03-251-0/+12
| | | | | | | | Warn for assignments inside of if-statement conditions. Task-number: QTBUG-129307 Change-Id: If1e4d85b6cdbf4f076d91dcf8d7600988f51d6a1 Reviewed-by: Ulf Hermann <[email protected]>
* qmllint: Implement ErrInvalidEnumValueSami Shalayel2025-03-211-1/+23
| | | | | | | | | | Implement the ErrInvalidEnumValue complaining about enum keys being lowercased or duplicated. Change the warning message as the Qt Creator code has a comment indicating that the message should be changed. Task-number: QTBUG-129307 Change-Id: If0b72eab38124453f90eb9a52e126bf9f24c83b7 Reviewed-by: Olivier De Cannière <[email protected]>
* Compiler: Fix various clazy warningsOlivier De Cannière2025-03-211-14/+17
| | | | | Change-Id: Ib83c8d3452d5a0521295750f068f429b414da6ff Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: warn about variable redeclarationSami Shalayel2025-03-191-7/+17
| | | | | | | | | | | Add a warning about variable redeclaration for 'let' and 'const' variables: they are not allowed in JS. Fixes: QTBUG-127107 Pick-to: 6.8 6.9 Change-Id: I44ba50e436b0b396a089bc8aedcef31d5455e48a Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* qmlls: don't mix up the in-memory and on-disk fileSami Shalayel2025-03-191-0/+21
| | | | | | | | | | | | | | | | | | | | | | | | | | Fix QQmlJSImportVisitor to register the scope into its QQmlJSImporter. This is important to avoid scope duplication. Before this patch, the implicit directory import that QQmlJSImportVisitor processes via QQmlJSImporter would create a duplicate "lazy" scope that reads from the file on disk during population. With this patch, QQmlJSImporter will know the current scope and therefore won't duplicate it during the implicit directory import. Add a test to qmlls to make sure that it can lint enums correctly, even if the enum declaration does not exist on the on-disk version. Avoid warnings while resolving scopes by marking the currently to be populated scope with the '$InProcess$' baseTypeName. It will be populated (including with its real base type name) after the import were processed. Pick-to: 6.9 6.8 Fixes: QTBUG-134781 Change-Id: I05cc8f8cab9279ee07c4a48a1b467738354e11dd Reviewed-by: Fabian Kosmale <[email protected]>
* qmllint: Warn about unsupported type annotationsFabian Kosmale2025-03-151-0/+11
| | | | | | | | | | | | It is currently not possilbe to have both type annotations and default parameters. As long as we don't implement support for them, qmllint should warn about them. Pick-to: 6.8 6.9 Task-number: QTBUG-104751 Change-Id: Ibec6f07f3ddb49f60ac20441a023e0c77d831422 Reviewed-by: Ulf Hermann <[email protected]>
* QML: Add final property attributeOlivier De Cannière2025-03-061-0/+2
| | | | | | | | | This works the same as the FINAL attribute to Q_PROPERTY. Task-number: QTBUG-98320 Change-Id: Icc2cf1afb5354fd711770f7147ded853b74cd1da Reviewed-by: Ulf Hermann <[email protected]> Reviewed-by: Sami Shalayel <[email protected]>
* Compiler: Don't make aliases to required properties required themselvesOlivier De Cannière2025-03-041-87/+166
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | When a property is declared as required, it needs to be bound when creating the component containing that type. Required properties can be aliased just like any other property. Before this patch, aliases targeting required properties would themselves be marked as required. This is incorrect as this forces the aliased required property to be set through the alias. It should be legal to alias a required property and not set required value through the alias. Therefore, stop marking the alias as required and instead check directly that the required property is bound in some scope for each object creation or that it is forwarded through a root-level alias. A required property will now also be satisfied if it is set through an alias. For this to work, a property alias now also stores its target scope and target property name. This change also adds checking for object definition bindings of the following form. These weren't checked before but really should be. ``` QtObject { property QtObject o: QtObject { required property int i // was not checked } } ``` These changes affect the way qmltc enforces setting required properties. Because it relied on aliases to required properties to be required themselves, it will now fail to enforce certain required properties. Created QTBUG-131777 and marked affected tests as QEXPECT_FAIL. Fixes: QTBUG-127098 Pick-to: 6.9 6.8 6.5 Change-Id: Ib36a43fbf3cc9c79eba6db39cbaf8769f85e2b31 Reviewed-by: Ulf Hermann <[email protected]>
* QmlCompiler: Tighten detection of assignment to unknown propertiesUlf Hermann2025-02-211-17/+16
| | | | | | | | | | | | | | While those properties may be of type Component, they don't have to. We can in fact not resolve anything resembling an ID while inside one of those objects because we cannot determine the component boundaries. Amends commit dea8e38d95508acd67da997d0c2a9c91ef1bc887 Pick-to: 6.9 6.8 Fixes: QTBUG-133460 Change-Id: Iac7294166d38ce591c45c0d31b139a52eda70fc1 Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* QmlCompiler: Only import hardcoded builtins by defaultUlf Hermann2025-02-181-2/+2
| | | | | | | | | | | | | | | | | | | | | | | | | At run time, not all the builtins are always available, but only those hardcoded into the parser. If we always import all the builtins at compile time, we introduce subtle errors when they shadow parts of the JavaScript global object. Now the builtins need to be actually imported. We cannot rely on the magic that adds them to the root scope of each document anymore. To this end, they need to become a regular module. The builtins are now loaded using a qmldir, just like any other module. The only thing special about is its "system" attribute which we now take to mean "read jsroot.qmltypes". Furthermore, the builtins get a "static" attribute so that we don't warn about them being unused. Even though they can now technically be unused, we really want people to still import them. Pick-to: 6.9 6.8 Fixes: QTBUG-133461 Change-Id: I322e14ba85c939773d36143ca24e88a7c9db23f5 Reviewed-by: Sami Shalayel <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]> Reviewed-by: Olivier De Cannière <[email protected]>
* qmllint: avoid wasteful didYouMean callsSami Shalayel2025-02-181-2/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | Add a new disabled mode to qqmljslogger that is used when warnings emitted by qqmljsimportvisitor are actually not shown to the user. Add a comment explaining the difference to a silenced logger (that still processes warnings and can be used to generate a JSON representation of the warnings) and a disabled logger (that does not contain any warning). Disable the logger in QQmlJSTypeReader that is only used for the (lazy file creation. This avoids expensive didYouMean() calls that slow down the linter and only create warnings that are ignored by the linter. Also add some ifs to qqmljslogger to avoid any useless computations when the logger is disabled anyway. This commit makes the runtime of tst_qmllint_benchmark:onlyQdsLintPlugin on qtdesign-studio/examples/DesignEffectsDemo/content/Gallery.ui.qml go from 500ms to 135ms (mean over 3 iterations) when the QtDesign studio modules import paths are unavailable. Task-number: QTBUG-133349 Change-Id: I5abaa5e6776e39f2dee7f1a92577a240dd5c61c1 Reviewed-by: Fabian Kosmale <[email protected]>