Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
confusing-minuses.qdoc
Go to the documentation of this file.
1
// Copyright (C) 2025 The Qt Company Ltd.
2
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4
/*!
5
\ingroup qmllint-warnings-and-errors
6
7
\title Confusing minuses
8
\brief [confusing-minuses] Confusing minuses.
9
10
\qmllintwarningcategory confusing-minuses
11
12
\section1 Confusing minuses
13
14
\section2 What happened?
15
JavaScript code uses a combination of operators written with '-' in a confusing
16
way. The neighboring '-' operators may be difficult to distinguish. This can be
17
made worse by unconventional spacing.
18
19
\section2 Why is that bad?
20
It makes the code more difficult to read and may cause confusion.
21
22
\section2 Example
23
\qml
24
import QtQuick
25
26
Item {
27
function f(a: int, b: int) {
28
let x = a-- - b
29
let y = a - -b
30
let z = a - --b
31
return x + y + z
32
}
33
}
34
\endqml
35
To fix this warning, rewrite the code so that it doesn't contain similar '-'
36
operators next to each other. Simplify expressions where possible. Remove
37
redundant unary operators and spacing, and use parentheses to isolate
38
subexpressions.
39
40
Be mindful that these operators may perform coercions. An expression like
41
\c{a - -b} may not be equivalent to \c{a + b} depending on the type of b.
42
\qml
43
import QtQuick
44
45
Item {
46
function f(a: int, b: int) {
47
let x = (a--) - b
48
let y = a + b
49
let z = a - b + 1
50
return x + y + z
51
}
52
}
53
\endqml
54
*/
qtdeclarative
src
qml
doc
src
qmllint
confusing-minuses.qdoc
Generated on
for Qt by
1.16.1