The body of an if, else or loop is a single statement without braces
What it finds
The body of an if, else or loop written without braces covers one statement only. A line added under it later, indented like the body, still runs every time.
An if that directly follows else is part of an else if chain and needs no braces. The fix puts the statement in braces.
From the rule's source, missing_braces.rs.
class Loops { int count(int[] values) { int n = 0; for (int v : values) n += v;tx0 reports: the body of this for has no braces if (n > 10) return 10;tx0 reports: the body of this if has no braces else if (n < 0) return 0;tx0 reports: the body of this if has no braces else n++;tx0 reports: the body of this else has no braces while (n > 5) { n--; } return n; }} 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/java:missing-braces" = "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/java:missing-braces] reason="..."tx0 explain tx0/java:missing-braces shows the same in the terminal. Found a false positive? Report it.