A statement is indented as if it belonged to the body of an if or loop without braces, but runs after it

tx0/c:misleading-indentationdefaultwarningbug

What it finds

``text if (err) log_error(err); return err; ``

The return is indented like the body of the if, but only the first statement is the body, so it runs every time. Braces around both, or the indentation of the code after the if, settle what is meant.

The body must start on a line after the head and be indented deeper than it, and the next statement must start on a line after the body, in the same column.

From the rule's source, misleading_indentation.rs.

Example from the rule's tests
void log_error(int err); int check(int err){  if (err)    log_error(err);    return err;tx0 reports: this statement is indented as if it were in the body above} int fine(int err){  if (err)    log_error(err);  return err;}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/c:misleading-indentation" = "off"

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/c:misleading-indentation] reason="..."

tx0 explain tx0/c:misleading-indentation shows the same in the terminal. Found a false positive? Report it.