// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only

/*!
\page qmllint-warnings-and-errors-assignment-in-condition.html
\ingroup qmllint-warnings-and-errors

\title Warn about using assignment in conditions
\brief [assignment-in-condition] An assignment statement is used inside a condition

\qmllintwarningcategory assignment-in-condition

\section1 Warn about using assignment in conditions

\section2 What happened?
You used an assignment inside an \c{if-condition}.

\section2 Why is this bad?
This is often a mistake, and a comparison should have been used. If it was intentional, it is still
often considered confusing.

\section2 Example
\qml
import QtQuick

Item {
    id: root
    Component.onCompleted: {
       // mistake: should have been a comparison
       if (width = height)
           console.log("A square")
       let mypoint = Qt.point(1,2)
       let hit = false
       // intentional, but possibly misleading
       if (hit = root.contains(myPoint))
           console.log("hit")
       root.enabled = hit
    }
}
\endqml

To fix this warning, change the assignment to a comparison if it was a mistake. Otherwise, wrap the
assignment into parentheses to indicate that it was done intentionally.

\qml
import QtQuick

Item {
    id: root
    Component.onCompleted: {
       // fixed
       if (width === height)
           console.log("A square")
       let mypoint = Qt.point(1,2)
       let hit = false
       // intentional
       if ((hit = root.contains(point)))
           console.log("hit")
       root.enabled = hit
    }
}
\endqml
*/

