Commit Graph

17 Commits

Author SHA1 Message Date
Fabian Kosmale dec2a22926 LinterVisitor: Allow construction without target
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>
2025-06-16 21:09:33 +02:00
Olivier De Cannière 2e00bc40cc qmllint: Warn about unintentional empty blocks
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>
2025-05-30 22:25:39 +02:00
Olivier De Cannière 005848a0c8 qmllint: Suggest specific types instead of var
A test was slightly adapted as a result.

Task-number: QTBUG-129307
Change-Id: I07ac61b183d9d7d237e9cf51ce3a0c6c280daa45
Reviewed-by: Sami Shalayel <sami.shalayel@qt.io>
2025-05-30 18:29:44 +02:00
Olivier De Cannière 7c97e932e1 qmllint: Warn about Components that don't have exactly one QML child
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>
2025-05-30 18:29:31 +02:00
Sami Shalayel b739545a12 qmllint: implement WarnConfusingExpressionStatement
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>
2025-05-22 17:27:54 +02:00
Olivier De Cannière 65804aaa92 qmllint: Warn about unterminated non-empty case blocks
Task-number: QTBUG-129307
Change-Id: I95f633299ca94cb27c545a97a465bb5e24b5e3e8
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
2025-05-19 20:41:03 +02:00
Olivier De Cannière f7a60386df qmllint: Warn about enums declared in non-root elements
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>
2025-05-19 20:41:03 +02:00
Olivier De Cannière ae3754df95 qmllint: Warn about enum entries matching the name of the enum itself
Fixes: QTBUG-117300
Task-number: QTBUG-119890
Change-Id: If503b3dbfe9c8ad916afa3b570861f62c33e1fbd
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2025-05-19 20:41:03 +02:00
Olivier De Cannière b44e844f4a qmllint: Move enum warnings to linting visitor and add warning category
The warnings should be part of the linting visitor.

Introduce a new warning category for the exising warning about
duplicate enum entries.

Amends bbce9ea73f

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 f368be4320

Task-number: QTBUG-119890
Change-Id: I90f280e2e443504ab336b4c2ad85bf7e53e4544f
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2025-05-19 20:41:03 +02:00
Olivier De Cannière bcbd2173dc qmllint: Warn about duplicate imports
Fixes: QTBUG-127325
Task-number: QTBUG-119890
Change-Id: I20b497da025dec8050ea94fc604db33a3ebdde77
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
2025-05-16 17:00:10 +02:00
Sami Shalayel 131cc998f7 qmllint: implement WarnConfusingPluses and Minuses
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>
2025-05-16 17:00:04 +02:00
Sami Shalayel 6d86e944f0 qmllint: implement WarnVoid
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>
2025-05-16 17:00:01 +02:00
Sami Shalayel 1950f29b88 qmllint: implement WarnXConstructor
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>
2025-05-16 16:59:57 +02:00
Sami Shalayel 76a29eee52 qmllint: implement WarnComma
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>
2025-05-16 16:59:53 +02:00
Sami Shalayel a8f0758c9c linterimportvisitor: add helper for parent nodes
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>
2025-05-16 16:59:46 +02:00
Sami Shalayel 5e024a7453 LinterImportVisitor: move linting code from QQmlJSImportVisitor
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>
2025-05-16 16:59:43 +02:00
Sami Shalayel 69a6ea8334 qqmljslinter: introduce LinterImportVisitor visitor
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>
2025-05-16 16:59:39 +02:00