A condition is an assignment, which may be a mistyped comparison
What it finds
if (user = current): an assignment where a condition is expected is often a comparison that lost an =.
The conditions of if, while, do-while and for are checked. Only assignments of a value that reads like the other side of a comparison are reported: a literal, a variable or a property. Assigning the result of a call and testing it, as in while (node = queue.shift()), is a common idiom and left alone, and so is an assignment wrapped in a second pair of parentheses, the usual way to say it is meant. Compound assignments such as += are not mistaken comparisons either.
From the rule's source, cond_assign.rs.
function find(user: { admin: boolean } | null, current: { admin: boolean }, queue: number[]) { if (user = current) {tx0 reports: user = current assigns; did you mean to compare? return 1; } let size = 0; while (size = 0) {tx0 reports: size = 0 assigns size++; } let item; while (item = queue.shift()) { size += item; } if ((user = current)) { return 2; } for (; size = current.admin ? 1 : 0;) { break; } return size;} Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/ts:cond-assign" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
// tx0: ignore[tx0/ts:cond-assign] reason="..."tx0 explain tx0/ts:cond-assign shows the same in the terminal. Found a false positive? Report it.