The indentation around a body without braces suggests other statements belong to it than do
What it finds
Without braces, the body of an if, else or loop is one statement, whatever the indentation says. Two layouts mislead: a body on its own line that is not indented deeper than its statement, which reads as if it always ran, and a statement after the body that is indented like the body, which reads as if it ran only with it.
From the rule's source, misleading_indentation.rs.
class Mislead { void run(boolean ready, int[] items) { if (ready) stop(); start();tx0 reports: indented like the body for (int item : items) use(item);tx0 reports: not indented deeper if (ready) stop(); start(); if (ready) stop(); start(); } void stop() {} void start() {} void use(int item) {}} 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/java:misleading-indentation" = "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:misleading-indentation] reason="..."tx0 explain tx0/java:misleading-indentation shows the same in the terminal. Found a false positive? Report it.