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\page qmllint-warnings-and-errors-confusing-minuses.html
6\ingroup qmllint-warnings-and-errors
7
8\title Confusing minuses
9\brief [confusing-minuses] Confusing minuses.
10
11\qmllintwarningcategory confusing-minuses
12
13\section1 Confusing minuses
14
15\section2 What happened?
16JavaScript code uses a combination of operators written with '-' in a confusing
17way. The neighboring '-' operators may be difficult to distinguish. This can be
18made worse by unconventional spacing.
19
20\section2 Why is that bad?
21It makes the code more difficult to read and may cause confusion.
22
23\section2 Example
24\qml
25import QtQuick
26
27Item {
28 function f(a: int, b: int) {
29 let x = a-- - b
30 let y = a - -b
31 let z = a - --b
32 return x + y + z
33 }
34}
35\endqml
36To fix this warning, rewrite the code so that it doesn't contain similar '-'
37operators next to each other. Simplify expressions where possible. Remove
38redundant unary operators and spacing, and use parentheses to isolate
39subexpressions.
40
41Be mindful that these operators may perform coercions. An expression like
42\c{a - -b} may not be equivalent to \c{a + b} depending on the type of b.
43\qml
44import QtQuick
45
46Item {
47 function f(a: int, b: int) {
48 let x = (a--) - b
49 let y = a + b
50 let z = a - b + 1
51 return x + y + z
52 }
53}
54\endqml
55*/