紛らわしいマイナス
この警告カテゴリのスペルは[confusing-minuses]
です。
紛らわしいマイナス
何が起こったのか?
JavaScriptのコードで、'-'で書かれた演算子の組み合わせが紛らわしく使われています。隣接する '-' 演算子を区別するのは難しいかもしれません。これは、型にはまった間隔によって悪化することがあります。
なぜ悪いのか?
コードが読みにくくなり、混乱を招く可能性があります。
例
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 } }
この警告を修正するには、似たような '-' 演算子が隣り合わせにならないようにコードを書き直します。可能な限り式を単純化する。冗長な単項演算子や空白を削除し、括弧を使って部分式を分離する。
これらの演算子は強制演算を行う可能性があることに注意してください。a - -b
のような式は、b の型によってはa + 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 } }
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.