Confusing minuses | Qt Qml | Qt 6.11.1
Description: [confusing-minuses] Confusing minuses.

- Qt 6.11
- Qt Qml
- Qt Qml Tooling
- qmllint
- QML Lint Warning and Errors
- Confusing minuses
- Qt 6.11.1 Reference Documentation

Comma ◦ Confusing pluses

# Confusing minuses

This warning category is spelled `[confusing-minuses]` by qmllint.

## Confusing minuses

### What happened?

JavaScript code uses a combination of operators written with '-' in a confusing way. The neighboring '-' operators may be difficult to distinguish. This can be made worse by unconventional spacing.

### Why is that bad?

It makes the code more difficult to read and may cause confusion.

### Example

     import QtQuick

     Item {
         function f(a: int, b: int) {
             let x = a-- - b
             let y = a - -b
             let z = a - --b
             return x + y + z
         }
     }

To fix this warning, rewrite the code so that it doesn't contain similar '-' operators next to each other. Simplify expressions where possible. Remove redundant unary operators and spacing, and use parentheses to isolate subexpressions.

Be mindful that these operators may perform coercions. An expression like `a - -b` may not be equivalent to `a + b` depending on the type of b.

     import QtQuick

     Item {
         function f(a: int, b: int) {
             let x = (a--) - b
             let y = a + b
             let z = a - b + 1
             return x + y + z
         }
     }

Comma ◦ Confusing pluses