A block stands among statements without a statement that owns it
What it finds
A block that stands on its own among statements, { ... } with no if or loop before it, only limits the scope of the variables inside. It is often a sign that the code inside wants to be a method of its own, or a leftover of a removed condition.
From the rule's source, bare_block.rs.
class Scopes { void run() { int a = 1; {tx0 reports: this block belongs to no statement int b = a + 1; } if (a > 0) { a--; } }} 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:bare-block" = "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:bare-block] reason="..."tx0 explain tx0/java:bare-block shows the same in the terminal. Found a false positive? Report it.