A branch of an if or else is empty and has no comment
What it finds
if cond {} else { work() } or else {}: an empty branch does nothing, so either the condition can be turned around and the branch dropped, or code that was meant to go there is missing. A comment in the branch says which.
Blocks of if and else with no statements and no comment are reported. The empty check of an error, if err != nil {}, is left to the rule empty-error-check, and loops with empty bodies to busy-wait.
From the rule's source, empty_branch.rs.
package p func f(ok bool, err error) int { if ok {} else {tx0 reports: the branch of this if is empty return 1 } if ok { return 2 } else {}tx0 reports: this else is empty if err != nil {} if ok { // Nothing to do: already done by the caller. } return 0} Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/go:empty-branch" = "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/go:empty-branch] reason="..."tx0 explain tx0/go:empty-branch shows the same in the terminal. Found a false positive? Report it.