A function has more return statements than the configured maximum
What it finds
A function that returns from many places is hard to follow: to know what it gives back, a reader has to find every exit and the conditions that lead to it.
Every return statement of the function counts, without those of nested functions. Guard clauses at the top of a function are a common and readable style, which is why this is a strict rule and the limit is generous. The limit is the parameter max (5 by default).
From the rule's source, return_count.rs.
function grade(score: number) {tx0 reports: grade returns from 6 places, more than 5 if (score > 90) return "A"; if (score > 80) return "B"; if (score > 70) return "C"; if (score > 60) return "D"; if (score > 50) return "E"; return "F";}function outer(items: number[]) { items.forEach((x) => { if (x) return; }); if (items.length) return 1; 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:return-count" = "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:return-count] reason="..."tx0 explain tx0/ts:return-count shows the same in the terminal. Found a false positive? Report it.