aboutsummaryrefslogtreecommitdiffstats
path: root/src/qmlcompiler/qqmljslintervisitor.cpp
Commit message (Collapse)AuthorAgeFilesLines
* 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 <[email protected]> Reviewed-by: Lars Schmertmann <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]> Reviewed-by: Fabian Kosmale <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>
* 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 <[email protected]>