The body of a control statement is a single statement without braces
What it finds
A body without braces holds exactly one statement, which is easy to forget when a second line is added with the same indentation: it then runs unconditionally. Braces make the extent of the body explicit.
Reported are bodies of if, else, for, while and do that are not blocks; an else if is a chain rather than a body and is left alone.
From the rule's source, missing_braces.rs.
export function f(items: number[]) { if (items.length) return 1;tx0 reports: this body has no braces for (const x of items) console.log(x);tx0 reports: this body has no braces if (items.length > 1) { return 2; } else if (items.length > 2) { return 3; } return 0;} 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/ts: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/ts:missing-braces] reason="..."tx0 explain tx0/ts:missing-braces shows the same in the terminal. Found a false positive? Report it.