The condition of an if, for or switch is wrapped in parentheses that Go does not need
What it finds
if (x > 0) {: Go's syntax needs no parentheses around conditions, and gofmt keeps them, so they stay as a habit from other languages that adds noise.
The whole condition must be one parenthesized expression. A condition containing a composite literal keeps its parentheses, since without them the opening brace of the literal would be read as the start of the block. The fix removes the parentheses and is safe.
From the rule's source, parenthesized_condition.rs.
package p func f(x int) int { if (x > 0) {tx0 reports: the parentheses around this condition are not needed return 1 } for (x < 10) {tx0 reports: the parentheses around this condition are not needed x++ } if (x > 0) && x < 5 { return 2 } return x} 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:parenthesized-condition" = "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:parenthesized-condition] reason="..."tx0 explain tx0/go:parenthesized-condition shows the same in the terminal. Found a false positive? Report it.