aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljslintervisitor.cpp
Commit message (Collapse)AuthorAgeFilesLines
* qmllint: reword warning about fall-throughsSami Shalayel6 days1-1/+4
| | | | | | | | | The current warning is a bit confusing, reword it to make it clearer and actually actionable. Task-number: QTBUG-138532 Change-Id: I1862fc9dd68135500a1b64f1440c770a97f47c02 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* Add security header for src/qmlcompilerOlivier De Cannière2025-09-171-0/+1
| | | | | | | | | | | | | | | | | | We assume that QML or JS code comes from a trusted source. Therefore, most files are deemed to be significant even if they parse data. This includes the source code itself but also the associated metadata or cache files. However, the QML compiler also generates C++ code. Extra care needs to be taken with the generator as a vulnerability there could propagate and have a disproportionate effect on the program's security. It is marked as critical. QUIP: 23 Fixes: QTBUG-136195 Pick-to: 6.10 6.9 6.8 Change-Id: I70630361ec8e9cb3969f78a3fdf36a41334a33b3 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: don't warn about fall-throughs where they don't happenSami Shalayel2025-07-291-5/+71
| | | | | | | | | | | | | | | | Iterate through the statements of the case-statements and don't warn about a fall-through if the code path of the case-statements return or break or throw before reaching the end of the case-block. Amends 65804aaa928bbf6467e22da4bd35fcae1373af2d that introduced the warning and only didn't check recursively for break, return or throw statements inside of case blocks. Pick-to: 6.10 Fixes: QTBUG-138532 Change-Id: I545898ebd52a4ec8f0ea58ca4ab5519e7137b6b0 Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io> Reviewed-by: Lars Schmertmann <SmallLars@t-online.de>
* qqmljsimportvisitor: give base types to attached scopesSami Shalayel2025-07-211-0/+3
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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 <fabian.kosmale@qt.io>
* LinterVisitor: Allow construction without targetFabian Kosmale2025-06-161-2/+2
| | | | | | | | | This mirrors the work on QQmlJSVisitor, and has the same reason: It becomes possible to track which calls update an existing scopes, and which calls create a new one. Change-Id: I98f13f8ed2da436510d11c0e2203ea4b23cdf8ed Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: Warn about unintentional empty blocksOlivier De Cannière2025-05-301-0/+16
| | | | | | | | | | If a property binding is a js block without any statements, it could mean that the user intended to create an object literal instead of an empty block that returns undefined. Task-number: QTBUG-129307 Change-Id: If242ddac140cce6479062194b785096ba1f6c0a6 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Suggest specific types instead of varOlivier De Cannière2025-05-301-0/+43
| | | | | | | | A test was slightly adapted as a result. Task-number: QTBUG-129307 Change-Id: I07ac61b183d9d7d237e9cf51ce3a0c6c280daa45 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: Warn about Components that don't have exactly one QML childOlivier De Cannière2025-05-301-0/+19
| | | | | | | | Two other tests needed to be updated as a result. Task-number: QTBUG-129307 Change-Id: I1470a5ae93cc20ef90ffd63471bd36408b61af57 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
* qmllint: implement WarnConfusingExpressionStatementSami Shalayel2025-05-221-0/+65
| | | | | | | | | | | | | | | Warn about ExpressionStatements that has no obvious effect in qmllint, for example "x * 3;" is an expression statement that is either useless or that potentially triggers user code with potential side-effects during the custom coercion of "x". Warn that the expression statement has no obvious effect. Don't warn about expression statements inside of bindings: "y: x * 3" is completely fine, for example. Task-number: QTBUG-129307 Change-Id: I065ddce7394276296062545c1516ab9b4ad9f24d Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Warn about unterminated non-empty case blocksOlivier De Cannière2025-05-191-0/+65
| | | | | | Task-number: QTBUG-129307 Change-Id: I95f633299ca94cb27c545a97a465bb5e24b5e3e8 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
* qmllint: Warn about enums declared in non-root elementsOlivier De Cannière2025-05-191-1/+5
| | | | | | | | Fixes: QTBUG-119781 Task-number: QTBUG-119890 Change-Id: I392819ad0a47e0457c4b888894893ac37a77fa11 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io> Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Warn about enum entries matching the name of the enum itselfOlivier De Cannière2025-05-191-0/+5
| | | | | | | Fixes: QTBUG-117300 Task-number: QTBUG-119890 Change-Id: If503b3dbfe9c8ad916afa3b570861f62c33e1fbd Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: Move enum warnings to linting visitor and add warning categoryOlivier De Cannière2025-05-191-0/+40
| | | | | | | | | | | | | | | | | | | | | 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 <fabian.kosmale@qt.io>
* qmllint: Warn about duplicate importsOlivier De Cannière2025-05-161-0/+34
| | | | | | | Fixes: QTBUG-127325 Task-number: QTBUG-119890 Change-Id: I20b497da025dec8050ea94fc604db33a3ebdde77 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: implement WarnConfusingPluses and MinusesSami Shalayel2025-05-161-0/+63
| | | | | | | | | | Implement the confusing pluses and minuses warnings. Those are triggered for weird combinations of unary pluses and pre increments inside of additions. (same for unary minuses and pre decrements). Task-number: QTBUG-129307 Change-Id: I45c202efa58a588090d872f0bf8f43523c24a957 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* qmllint: implement WarnVoidSami Shalayel2025-05-161-0/+7
| | | | | | | | | Warn about usages of the void keyword. This warning is off by default, mirroring the behavior of eslint. Task-number: QTBUG-129307 Change-Id: Iba1cc09e028d5053ef1aa28f01f1694efa5c250f Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmllint: implement WarnXConstructorSami Shalayel2025-05-161-0/+22
| | | | | | | | | Implement the WarnXConstructor and complain about a specific set of constructors. Task-number: QTBUG-129307 Change-Id: I27e0cfcb1f061bb2efff1721da4a2bbdb01fcf2f Reviewed-by: Semih Yavuz <semih.yavuz@qt.io>
* qmllint: implement WarnCommaSami Shalayel2025-05-161-0/+14
| | | | | | | | Warn when comma expressions are used outside of for-loops. Task-number: QTBUG-129307 Change-Id: Ic86bf3af7f122f73b70e18c728c72f64c355f982 Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
* linterimportvisitor: add helper for parent nodesSami Shalayel2025-05-161-0/+19
| | | | | | | | | Add a helper to retrieve the parent of the current node. It will be needed in later commits to emit warnings. Task-number: QTBUG-129307 Change-Id: Iaf6acd55db67e549ca8f34b5e20bf069d12349dd Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* LinterImportVisitor: move linting code from QQmlJSImportVisitorSami Shalayel2025-05-161-0/+45
| | | | | | | | | Move the stringliteral linting code into the new LinterImportVisitor class. Task-number: QTBUG-129307 Change-Id: I5f358f91c41e99383582be9fc1628814563848ed Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>
* qqmljslinter: introduce LinterImportVisitor visitorSami Shalayel2025-05-161-0/+19
Add a visitor that creates warnings about qml and js code, to avoid having all the warning-related but qqmljsscope-unrelated code in qqmljsimportvisitor. Task-number: QTBUG-129307 Change-Id: Icf56979d99855f11c5e72a0c9efbf9ecd629e42e Reviewed-by: Olivier De Cannière <olivier.decanniere@qt.io>