A block is empty
What it finds
if (ready) {}, try { ... } finally {}, switch (x) {}: a block with nothing in it does nothing, which usually means code was left out or removed and the shell kept.
Blocks with a comment inside say why they are empty and are left alone. So are the bodies of functions and loops, where an empty body is a common way to write a no-op or a loop that does its work in its head, and catch clauses, which empty-catch covers. An empty if branch followed by an else is reported too: the condition is better negated.
From the rule's source, empty_block.rs.
function run(ready: boolean, items: number[]) { if (ready) {}tx0 reports: this branch is empty if (ready) { start(); } else {}tx0 reports: this branch is empty try {} finally {tx0 reports: this try block is empty stop(); } if (ready) { /* nothing to do yet */ } for (const item of items) {} while (ready) {} switch (items.length) {}tx0 reports: this switch has no cases}function start() {}function stop() {}class Registry { static {}tx0 reports: this static block is empty} 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/ts:empty-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/ts:empty-block] reason="..."tx0 explain tx0/ts:empty-block shows the same in the terminal. Found a false positive? Report it.