A return or continue at the end of its body changes nothing
What it finds
A return; as the last statement of a function, or a continue; as the last statement of a loop body, jumps to where the code goes next anyway. It adds a line that a reader has to check for a purpose it does not have.
Only a return without a value and a continue without a label count, as the last statement directly in the body block, after other statements: a body that holds nothing but return; is a deliberate no-op. The fix, which is safe, removes the statement.
From the rule's source, pointless_final_jump.rs.
function f(a: number[]) { for (const x of a) { if (x) { continue; } a.push(x); continue;tx0 reports: this continue is the last statement } if (a.length) { return; } a.pop(); return;tx0 reports: this return is the last statement}function g(a: number) { return a;} 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:pointless-final-jump" = "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:pointless-final-jump] reason="..."tx0 explain tx0/ts:pointless-final-jump shows the same in the terminal. Found a false positive? Report it.