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

- Qt 6.10
- Qt Qml
- QML Lint Warning and Errors
- Confusing minuses
- Qt 6.10.3 Reference Documentation

# 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
         }
     }